Source File
lock.go
Belonging Package
go.pact.im/x/supervisor
package supervisorimport ()// chanLock is a mutually exclusive lock that supports canceling acquire operation.type chanLock chan struct{}// newChanLock returns a new Lock that allows at most one goroutine to acquire it.func () chanLock {return make(chanLock, 1)}// Acquire locks c. If the lock is already in use, the calling goroutine blocks// until either the lock is available or the context expires. It returns nil// if the lock was acquired and a non-nil context error otherwise.func ( chanLock) ( context.Context) error {select {case <-.Done():return .Err()case <- struct{}{}:return nil}}// Release unlocks c. Unlike sync.Mutex, it is valid to release a Lock without// a corresponding Acquire. In that case the next Acquire call will unlock the// Release.func ( chanLock) () {<-}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)