Locker facilitates synchronization across machines and networks. It essentially provides a distributed named-mutex service so that multiple consumers can coordinate tasks and share resources. If possible, a Locker should implement a coordinated distributed locking mechanism by generating fencing to
| 127 | // operations across nodes in a cluster; not for internal, extremely |
| 128 | // short-lived, or high-contention locks. |
| 129 | type Locker interface { |
| 130 | // Lock acquires the lock for name, blocking until the lock |
| 131 | // can be obtained or an error is returned. Only one lock |
| 132 | // for the given name can exist at a time. A call to Lock for |
| 133 | // a name which already exists blocks until the named lock |
| 134 | // is released or becomes stale. |
| 135 | // |
| 136 | // If the named lock represents an idempotent operation, callers |
| 137 | // should always check to make sure the work still needs to be |
| 138 | // completed after acquiring the lock. You never know if another |
| 139 | // process already completed the task while you were waiting to |
| 140 | // acquire it. |
| 141 | // |
| 142 | // Implementations should honor context cancellation. |
| 143 | Lock(ctx context.Context, name string) error |
| 144 | |
| 145 | // Unlock releases named lock. This method must ONLY be called |
| 146 | // after a successful call to Lock, and only after the critical |
| 147 | // section is finished, even if it errored or timed out. Unlock |
| 148 | // cleans up any resources allocated during Lock. Unlock should |
| 149 | // only return an error if the lock was unable to be released. |
| 150 | Unlock(ctx context.Context, name string) error |
| 151 | } |
| 152 | |
| 153 | type TryLocker interface { |
| 154 | // TryLock attempts to acquire the lock for name, and returns a |
no outgoing calls
no test coverage detected
searching dependent graphs…