/// <summary>Add Cancellation Triggers on destroy</summary> public void AddCancellationTriggerOnDestory(CancellationTokenSource cts) { if (called) { cts.Cancel(); cts.Dispose(); } if (canellationTokenSourceOrQueue == null) { canellationTokenSourceOrQueue = cts; } else if (canellationTokenSourceOrQueue is CancellationTokenSource c) { var q = new MinimumQueue<CancellationTokenSource>(4); q.Enqueue(c); q.Enqueue(cts); canellationTokenSourceOrQueue = q; } else { ((MinimumQueue<CancellationTokenSource>)canellationTokenSourceOrQueue).Enqueue(cts); } }
public void Add(ITriggerHandler <T> handler) { if (isRunning) { if (waitHandler == null) { waitHandler = handler; return; } if (waitQueue == null) { waitQueue = new MinimumQueue <ITriggerHandler <T> >(4); } waitQueue.Enqueue(handler); return; } if (singleHandler == null) { singleHandler = handler; } else { if (handlers == null) { handlers = new ITriggerHandler <T> [4]; } // check empty for (int i = 0; i < handlers.Length; i++) { if (handlers[i] == null) { handlers[i] = handler; return; } } // full, ensure capacity var last = handlers.Length; { EnsureCapacity(ref handlers); handlers[last] = handler; } } }
private Task RegisterActionAsyncCore(LooperAction action) { lock (_lockQueue) { if (_isRunning) { _registerQueue.Enqueue(action); return(action.Future.Task); } } lock (_lockActions) { if (_actions.Length == _tail) { Array.Resize(ref _actions, checked (_tail * _growFactor)); } _actions[_tail++] = action; } return(action.Future.Task); }