package syncx

import (
	
)

// Lock is a mutually exclusive lock that supports cancelling acquire operation.
type Lock chan struct{}

// NewLock returns a new Lock that allows at most one goroutine to acquire it.
func () Lock {
	return make(Lock, 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 ( Lock) ( 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 ( Lock) () {
	<-
}