Skip to content

Commit b1e4553

Browse files
authored
context: support for wrapping with timeout (#2)
1 parent e6f9725 commit b1e4553

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

context.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ func Cancelable() (C, Cancel) {
3737
func WithCancel(c C) (C, Cancel) {
3838
return context.WithCancel(c)
3939
}
40+
41+
// WithTTL wraps an existing Context that will expire after the given duration.
42+
func WithTTL(c C, duration time.Duration) (C, Cancel) {
43+
return context.WithTimeout(c, duration)
44+
}

0 commit comments

Comments
 (0)