Created
November 29, 2020 04:51
-
-
Save enjoylife/847ef74b579525a5555fb20cd229a6d9 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
func withTimeout(ctx context.Context, f func(context.Context) error) error { | |
c := make(chan error, 1) | |
go func() { c <- f(ctx) }() | |
select { | |
case <-ctx.Done(): | |
return ctx.Err() | |
case err := <-c: | |
return err | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment