Skip to content

Instantly share code, notes, and snippets.

@KauzClay

KauzClay/main.go Secret

Last active February 22, 2022 17:53
Show Gist options
  • Save KauzClay/abf3fe664e6867bca90dc16c8a11f594 to your computer and use it in GitHub Desktop.
Save KauzClay/abf3fe664e6867bca90dc16c8a11f594 to your computer and use it in GitHub Desktop.
Exploring CleanupOnInterrupt: go run main.go and ctrl-C after it says sleeping. You should see both cleanup functions.
package main
import (
"fmt"
"time"
pkgtest "knative.dev/pkg/test"
)
func main() {
pkgtest.CleanupOnInterrupt(func() {
fmt.Println("I am cleanup function 1")
}, nil)
pkgtest.CleanupOnInterrupt(func() {
fmt.Println("I am cleanup function 2")
}, nil)
doSomeStuff()
fmt.Println("sleeping, interrupt me")
time.Sleep(30 * time.Second)
fmt.Println("awake")
}
func doSomeStuff() {
fmt.Println("doing stuff")
pkgtest.CleanupOnInterrupt(func() {
fmt.Println("I am cleanup function 3")
}, nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment