/// <inheritdoc /> public override T Take() { IPoolContracts.Take(this); var result = base.Take(); this.IncrementTakenCount(); return(result); }
/// <inheritdoc /> public override async Task <T> TakeAsync() { IPoolContracts.TakeAsync(this); var result = await base.TakeAsync().DontMarshallContext(); this.IncrementTakenCount(); return(result); }
/// <inheritdoc /> public void Give(T value) { IPoolContracts.Give(this); this.resetAction(value); if (!this.buffer.Post(value)) { this.releaseAction(value); } }
/// <inheritdoc /> public override Task <T> TakeAsync() { IPoolContracts.TakeAsync(this); T value; if (this.TryTake(out value)) { return(Task.FromResult(value)); } return(Task.FromResult(this.factory.Create())); }
/// <inheritdoc /> public override T Take() { IPoolContracts.Take(this); T value; if (this.TryTake(out value)) { return(value); } return(this.factory.Create()); }
/// <inheritdoc /> public override async Task <T> TakeAsync() { IPoolContracts.TakeAsync(this); T value; if (this.TryTake(out value)) { return(value); } return(await this.factory.CreateAsync().DontMarshallContext()); }
/// <inheritdoc /> public override bool TryTake(out T value) { IPoolContracts.TryTake(this); if (base.TryTake(out value)) { this.IncrementTakenCount(); return(true); } else { return(false); } }
/// <inheritdoc /> public override void Give(T value) { IPoolContracts.Give(this); base.Give(value); this.givenCountChanged.OnNext(this.givenCount.Increment()); long onLoan; if (this.onLoanCount.TryDecrementClampLower(0, out onLoan)) { this.onLoanCountChanged.OnNext(onLoan); } }
/// <inheritdoc /> public override async Task <T> TakeAsync() { IPoolContracts.TakeAsync(this); T value; if (this.TryTake(out value)) { return(value); } if (this.countLeft?.TryDecrementClampLower(0) ?? true) { return(this.factory.Create()); } return(await this.Pool.TakeAsync().DontMarshallContext()); }
/// <inheritdoc /> public override T Take() { IPoolContracts.Take(this); T value; if (this.TryTake(out value)) { return(value); } if (this.countLeft?.TryDecrementClampLower(0) ?? true) { return(this.factory.Create()); } return(this.Pool.Take()); }
/// <inheritdoc /> public TValue Take() { IPoolContracts.Take(this); TValue value; if (this.TryTake(out value)) { return(value); } else { this.awaitingTokensCount.Increment(); try { return(this.pool.Take()); } finally { this.awaitingTokensCount.Decrement(); } } }
/// <inheritdoc /> public bool TryTake(out TValue value) { IPoolContracts.TryTake(this); while (true) { if (this.pool.TryTake(out value)) { return(true); } else { // unable to TryTake from the pool so try disposing a token // to release a value back to the pool if (!this.stash.TryExpireToken()) { // unable to release any more values back to the pool // so TryTake can't succeed return(false); } } } }
/// <inheritdoc /> public async Task <TValue> TakeAsync() { IPoolContracts.TakeAsync(this); TValue value; if (this.TryTake(out value)) { return(value); } else { this.awaitingTokensCount.Increment(); try { return(await this.pool.TakeAsync().DontMarshallContext()); } finally { this.awaitingTokensCount.Decrement(); } } }
/// <inheritdoc /> public virtual void Give(T value) { IPoolContracts.Give(this); this.Pool.Give(value); }
/// <inheritdoc /> public virtual Task <T> TakeAsync() { IPoolContracts.TakeAsync(this); return(this.Pool.TakeAsync()); }
/// <inheritdoc /> public virtual T Take() { IPoolContracts.Take(this); return(this.Pool.Take()); }
/// <inheritdoc /> public virtual bool TryTake(out T value) { IPoolContracts.TryTake(this); return(this.Pool.TryTake(out value)); }
/// <inheritdoc /> public Task <T> TakeAsync() { IPoolContracts.TakeAsync(this); return(this.buffer.ReceiveAsync()); }
/// <inheritdoc /> public T Take() { IPoolContracts.Take(this); return(this.buffer.Receive()); }
/// <inheritdoc /> public bool TryTake(out T value) { IPoolContracts.TryTake(this); return(this.buffer.TryReceive(out value)); }
/// <inheritdoc /> public void Give(TValue value) { IPoolContracts.Give(this); this.pool.Give(value); }