Source File
detach.go
Belonging Package
github.com/teivah/onecontext
package onecontextimport ()// DetachedContext holds the logic to detach a cancellation signal from a context.type DetachedContext struct {ctx context.Contextch chan struct{}cancel func()}// Detach detaches the cancellation signal from a context.func ( context.Context) (*DetachedContext, func()) {:= make(chan struct{}):= func() {close()}return &DetachedContext{ctx: ,ch: ,cancel: ,},}// Deadline returns a nil deadline.func ( *DetachedContext) () (time.Time, bool) {return time.Time{}, false}// Done returns a cancellation signal that expires only when the context is canceled from the cancel function returned in Detach.func ( *DetachedContext) () <-chan struct{} {return .ch}// Err returns an error if the context is canceled from the cancel function returned in Detach.func ( *DetachedContext) () error {select {case <-.Done():return ErrCanceleddefault:return nil}}// Value returns the value associated with the key from the original context.func ( *DetachedContext) ( interface{}) interface{} {return .ctx.Value()}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |