private async Task SubscribeBlock(InQueueBlock <TCriteria, TActionArg> block) { try { var disposable = await provider.Subscribe(block.Criteria, candle => { if (block.CanReceiveUpdates) { block.OnNextAction(candle); } }, error => { ReportBlockError(block, error); }) .ConfigureAwait(false); block.TryMarkAsAlive(disposable); } catch (Exception e) { if (block.CanReceiveErrors) { ReportBlockError(block, e); } else { NotifyException(e); } } }
private static void ReportBlockError(InQueueBlock <TCriteria, TActionArg> block, Exception error) { if (block.CanReceiveErrors) { block.ErrorAction(error); } }
public Task <IDisposable> Subscribe(TCriteria criteria, Action <TActionArg> onNextAction, Action <Exception> errorAction) { var block = new InQueueBlock <TCriteria, TActionArg>(criteria, onNextAction, errorAction); var disposable = new FridayDisposable(() => { block.MarkBlockAsNonUsable(); }); lock (actualBlocks) actualBlocks.Add(block); return(Task.FromResult <IDisposable>(disposable)); }