Standard library / context

context.CancelFunc

Function requesting cancellation; repeated calls have no effect. It does not wait for workers to stop. Expected stdout: 'context canceled\n'.

Formal Syntax & Structure

go syntaxgo
type CancelFunc func()

Working Example

Example Snippetgo
package main
import (  "context"  "fmt")
func main() {  ctx, cancel := context.WithCancel(context.Background())  var f context.CancelFunc = cancel  f()  f()  <-ctx.Done()  fmt.Println(ctx.Err())}
Go Reference