Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from goinsane/develop
Browse files Browse the repository at this point in the history
v1.5.3
  • Loading branch information
orkunkaraduman authored Mar 4, 2022
2 parents ec92eda + cb1818e commit 8497797
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions terminatecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ type terminateContext struct {
context.CancelFunc
}

// Terminate calls cancel function of the underlying context.
func (c *terminateContext) Terminate() {
c.CancelFunc()
}

// WithTerminate creates a new TerminateContext.
// NewTerminateContext returns the underlying context as TerminateContext.
// The code should call Terminate method or cancel function to release resources associated with it.
func NewTerminateContext(ctx context.Context, cancel context.CancelFunc) TerminateContext {
result := new(terminateContext)
result.Context = ctx
result.CancelFunc = cancel
return result
}

// WithTerminate creates a new cancel context as TerminateContext.
// The code should call Terminate method to release resources associated with it, as cancel function.
func WithTerminate(parent context.Context) TerminateContext {
ctx := new(terminateContext)
ctx.Context, ctx.CancelFunc = context.WithCancel(parent)
return ctx
return NewTerminateContext(context.WithCancel(parent))
}

0 comments on commit 8497797

Please sign in to comment.