Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "context"
- "fmt"
- "time"
- )
- func main() {
- ctx, cancel := context.WithCancel(context.Background())
- go func() {
- select {
- case <-ctx.Done():
- fmt.Printf("%v Cancelled \n", time.Now().String())
- case <-time.After(1 * time.Microsecond):
- fmt.Printf("%v Run \n", time.Now().String())
- }
- }()
- fmt.Printf("%v Start\n", time.Now().String())
- time.Sleep(2 * time.Microsecond)
- fmt.Printf("%v Finish\n", time.Now().String())
- cancel()
- time.Sleep(1 * time.Microsecond)
- fmt.Printf("%v Exit\n", time.Now().String())
- }
Add Comment
Please, Sign In to add comment