Documentation
¶
Overview ¶
Package ctxlock provides context aware lock
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock implements ordinary exclusive lock.
type SharableLock ¶
type SharableLock struct {
// contains filtered or unexported fields
}
SharableLock implements exclusive lock for writer and shared lock for reader.
func NewSharableLock ¶
func NewSharableLock() *SharableLock
NewSharableLock creates a new SharableLock and returns the pointer to it.
func (*SharableLock) ExclusiveLock ¶
func (L *SharableLock) ExclusiveLock(ctx context.Context) (UnlockFunc, error)
ExclusiveLock tries to lock for writer and returns unlock function when it succeed. If ctx is canceled, lock is canceled and context.Cause(ctx) error is returned.
func (*SharableLock) SharedLock ¶
func (L *SharableLock) SharedLock(ctx context.Context) (UnlockFunc, error)
SharedLock tries to lock for reader and returns unlock function when it succeed. If ctx is canceled, lock is canceled and context.Cause(ctx) error is returned.
type UnlockFunc ¶
type UnlockFunc func()
func (UnlockFunc) UnlockOnCancel ¶
func (f UnlockFunc) UnlockOnCancel(ctx context.Context)
UnlockOnCancel schedules to call unlock when ctx cancels. If the ctx has already been canceled, unlock is called immediately.