Created
July 30, 2020 11:25
-
-
Save maxwellgithinji/0f65892cb4e5bd7581f8c64efcb009c4 to your computer and use it in GitHub Desktop.
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 ( | |
"context" | |
"fmt" | |
"time" | |
) | |
func main() { | |
ctx := context.Background() | |
ctx, cancelF := context.WithTimeout(ctx, 100*time.Millisecond) | |
defer cancelF() | |
time.Sleep(50 * time.Millisecond) | |
select { | |
case <-ctx.Done(): | |
fmt.Println("not finished") | |
default: | |
fmt.Println("finished") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment