Suspends execution until the task finishes or caller is cancelled. Can be called from coroutine context only. For non-coroutine context use BlockingWait().
template<typename Rep , typename Period >
void
WaitFor (const std::chrono::duration< Rep, Period > &) const noexcept(false)
Suspends execution until the task finishes or after the specified timeout or until caller is cancelled.
Suspends execution until the task finishes or until the specified deadline is reached or until caller is cancelled.
void
RequestCancel ()
Queues task cancellation request.
void
SyncCancel () noexcept
Cancels the task and suspends execution until it is finished. Can be called from coroutine context only. For non-coroutine context use RequestCancel() + BlockingWait().
A task that tries to acquire a distributed lock and runs user callback once while the lock is held.
When dist lock starts, the lock worker tries to take a lock in the loop. If succeeded, a task is launched that executes the user code. In the background, dist lock tries to extend the lock. In case of loss of the lock, the user task is canceled.
Example with retrying
auto strategy = GetSomeDistLockStrategyForTheSample();
a callback that is started once we've acquired the lock and is cancelled when the lock is lost.
settings
distributed lock settings
strategy
distributed locking strategy
mode
distributed lock waiting mode
Note
worker_func must honour task cancellation and stop ASAP when it is cancelled, otherwise brain split is possible (IOW, two different users do work assuming both of them hold the lock, which is not true).