Skip to content

Instantly share code, notes, and snippets.

@maxwellgithinji
Created July 30, 2020 11:25
Show Gist options
  • Save maxwellgithinji/0f65892cb4e5bd7581f8c64efcb009c4 to your computer and use it in GitHub Desktop.
Save maxwellgithinji/0f65892cb4e5bd7581f8c64efcb009c4 to your computer and use it in GitHub Desktop.
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