/// <inheritdoc /> public async Task HandleEventAsync(ProtocolEvent ev, bool processNow) { var callback = new TaskCompletionSource <bool>(); await _enqueueBlock.SendAsync(new Tuple <TaskCompletionSource <bool>, ProtocolEvent, bool>(callback, ev, processNow)).ConfigureAwait(false); // continuewith very important because otherwise continuations run synchronously // https://stackoverflow.com/q/34658258/10896275 var task = callback.Task.ContinueWith(x => x.Result, TaskScheduler.Default); await task.ConfigureAwait(false); }
/// <inheritdoc /> public async Task ScheduleEventAsync(ProtocolEvent ev, bool processNow) { var sent = await _enqueueBlock .SendAsync(new Tuple <TaskCompletionSource <bool>, ProtocolEvent, bool>(null, ev, processNow)) .ConfigureAwait(false); if (!sent) { throw new DriverInternalError("Could not schedule event in the ProtocolEventDebouncer."); } }
private void MainEventReceived(ProtocolEvent ev, bool processNow, TaskCompletionSource <bool> callback) { if (_queue == null) { _queue = new EventQueue(); } _queue.MainEvent = ev; if (callback != null) { _queue.Callbacks.Add(callback); } _timer.SlideDelay(processNow); }
/// <inheritdoc /> public Task ScheduleEventAsync(ProtocolEvent ev, bool processNow) { return(_enqueueBlock.SendAsync(new Tuple <TaskCompletionSource <bool>, ProtocolEvent, bool>(null, ev, processNow))); }