Skip to content

Instantly share code, notes, and snippets.

@harunpeksen
Last active March 6, 2022 14:12
Show Gist options
  • Save harunpeksen/969aef7ba74761aa4722b729f4dc222a to your computer and use it in GitHub Desktop.
Save harunpeksen/969aef7ba74761aa4722b729f4dc222a to your computer and use it in GitHub Desktop.
// Setting a deadline
clientDeadline := time.Now().Add(time.Duration(*deadlineMs) * time.Millisecond)
ctx, cancel := context.WithDeadline(ctx, clientDeadline)
// Checking deadline
if ctx.Err() == context.Canceled {
return status.New(codes.Canceled, "Client cancelled, abandoning.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment