public static async Task <EventCanceller> AddCancellableEvent(IEvent @event) { var executor = new EventExecutor(@event); var eventCanceller = executor.GetEventCanceller(); await executor.StartEvent(); return(eventCanceller); }
public async Task OnStarted(EventExecutor executor) { EventCanceller?oldCanceller; lock (_runningDeadlinesLock) { _runningDeadlines.TryGetValue(TicketId, out oldCanceller); } // old canceller cannot be awaited in the lock if (oldCanceller != null) { await oldCanceller.Cancel(); } lock (_runningDeadlinesLock) { // Get a canceller from the EventExecutor and update the index _runningDeadlines[TicketId] = executor.GetEventCanceller(); } Console.WriteLine($"Set Deadline of Ticket {TicketId} to {Time}"); }