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 #16 from goinsane/develop
Browse files Browse the repository at this point in the history
v1.5.3-rev0
  • Loading branch information
orkunkaraduman authored Mar 4, 2022
2 parents 8497797 + 7e6f947 commit 86a68eb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions terminatecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,25 @@ func (c *terminateContext) Terminate() {
// 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
result.Context, result.CancelFunc = ctx, cancel
return result
}

// NewTerminateContext2 is similar with NewTerminateContext.
// But it cancels the context when it was done through parent, deadline, timeout or in any way.
func NewTerminateContext2(ctx context.Context, cancel context.CancelFunc) TerminateContext {
AutoCancel(ctx, cancel)
return NewTerminateContext(ctx, cancel)
}

// 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 {
return NewTerminateContext(context.WithCancel(parent))
}

// WithTerminate2 is similar with WithTerminate.
// But it cancels the context when it was done through parent.
func WithTerminate2(parent context.Context) TerminateContext {
return NewTerminateContext(WithCancel(parent))
}

0 comments on commit 86a68eb

Please sign in to comment.