-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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