Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v16] add
services.AcquireSemaphoreLockWithRetry
(#42631)
* transform `services.SemaphoreLock` to satisfy `context.Context` This PR makes `services.SemaphoreLock` statisfy the `context.Context` interface. Extending the `services.SemaphoreLock` makes it possible to use the lease as a context in context propgation. ```go lease, err:=services.AcquireSemaphore(ctx,...) if err!=nil{ ... } ctx, cancel:=context.WithCancel(lease) ``` `lease` is released when the semaphore lock is lost or when the parent context is cancelled so we can use it as argument to other context functions without having to carry the parent context. Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> * use ctx.Done channel from stdlib context to avoid spining a goroutine * add `services.AcquireSemaphoreLockWithRetry` This PR introduces `services.AcquireSemaphoreLockWithRetry` function that only returns if it sucessfully acquired the lock or if the parent context is cancelled. This function will retry until it sucessfully acquires the lock before returning. Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> * Update lib/services/semaphore.go Co-authored-by: Edward Dowling <EdwardDowling@users.noreply.github.com> --------- Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> Co-authored-by: Edward Dowling <EdwardDowling@users.noreply.github.com>
- Loading branch information