private void Notify(int count) { for (int i = 0; i < count; i++) { if (!_buyers.TryDequeue(out var buyer)) { break; } _readyForService.Add(buyer); Availabled?.Invoke(this, new ObjectAvailabledEventArgs(buyer.Id)); } }
public IReadOnlyCollection <Product> TakeAnyProducts(int count, IReadOnlyBuyer buyer) { if (buyer == null) { throw new ArgumentNullException(nameof(buyer)); } if (!IsAvailable()) { throw new ShelfIsBusyException(); } _semaphoreSlim.Wait(); var result = TakeProductInternal(count, buyer); _semaphoreSlim.Release(); Availabled?.Invoke(this, EventArgs.Empty); return(result); }
public Receipt MakePurchases(IReadOnlyBuyer buyer) { if (buyer == null) { throw new ArgumentNullException(nameof(buyer)); } if (!IsAvailable()) { throw new CashboxIsBusyException(); } _semaphoreSlim.Wait(); MakePurchasesInternal(buyer); var result = new Receipt(Supermarket, buyer.Basket.Products); _semaphoreSlim.Release(); Availabled?.Invoke(this, EventArgs.Empty); return(result); }