| 18 | } |
| 19 | |
| 20 | TFuture<TAsyncSemaphore::TPtr> TAsyncSemaphore::AcquireAsync() { |
| 21 | with_lock(Lock_) { |
| 22 | if (Cancelled_) { |
| 23 | return MakeErrorFuture<TPtr>( |
| 24 | std::make_exception_ptr(TOperationCancelledException())); |
| 25 | } |
| 26 | if (Count_) { |
| 27 | --Count_; |
| 28 | return MakeFuture<TAsyncSemaphore::TPtr>(this); |
| 29 | } |
| 30 | auto promise = NewPromise<TAsyncSemaphore::TPtr>(); |
| 31 | Promises_.push_back(promise); |
| 32 | return promise.GetFuture(); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | void TAsyncSemaphore::Release() { |
| 37 | TPromise<TPtr> promise; |