All long, blocking operations take context.Context
Context is a standard way to give users of your library control over when actions should be interrupted.
and related:
Allow clean shutdown of background goroutines
This is a preferred restriction on Goroutine lifetimes feedback. There should be a way to end any goroutines your library creates, in a way that won’t signal spurious errors.
and related:
From: https://medium.com/@cep21/aspects-of-a-good-go-library-7082beabb403