Documentation ¶
Overview ¶
Package memlock allows multiple appengine handlers to coordinate best-effort mutual execution via memcache. "best-effort" here means "best-effort"... memcache is not reliable. However, colliding on memcache is a lot cheaper than, for example, colliding with datastore transactions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyClientID = errors.New("memlock: empty clientID")
ErrEmptyClientID is returned from TryWithLock when you specify an empty clientID.
var ErrFailedToLock = errors.New("memlock: failed to obtain lock")
ErrFailedToLock is returned from TryWithLock when it fails to obtain a lock prior to invoking the user-supplied function.
Functions ¶
func TryWithLock ¶
TryWithLock attempts to obtains the lock once, and then invokes f if successful. The context provided to f will be canceled (e.g. ctx.Done() will be closed) if memlock detects that we've lost the lock.
TryWithLock function returns ErrFailedToLock if it fails to obtain the lock, otherwise returns the error that f returns.
`key` is the memcache key to use (i.e. the name of the lock). Clients locking the same data must use the same key. clientID is the unique identifier for this client (lock-holder). If it's empty then TryWithLock() will return ErrEmptyClientID.
Note that the lock provided by TryWithLock is a best-effort lock... some other form of locking or synchronization should be used inside of f (such as Datastore transactions) to ensure that f is, in fact, operating exclusively. The purpose of TryWithLock is to have a cheap filter to prevent unnecessary contention on heavier synchronization primitives like transactions.
Types ¶
This section is empty.