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); }
/// <summary> /// Registers a loop-frame action with state object to the looper and returns <see cref="Task"/> to wait for completion. /// </summary> /// <param name="loopAction"></param> /// <param name="state"></param> /// <returns></returns> public Task RegisterActionAsync <TState>(LogicLooperActionWithStateDelegate <TState> loopAction, TState state) { var action = new LooperAction(DelegateHelper.GetWrapper <TState>(), loopAction, state); return(RegisterActionAsyncCore(action)); }
/// <summary> /// Registers a loop-frame action to the looper and returns <see cref="Task"/> to wait for completion. /// </summary> /// <param name="loopAction"></param> /// <returns></returns> public Task RegisterActionAsync(LogicLooperActionDelegate loopAction) { var action = new LooperAction(DelegateHelper.GetWrapper(), loopAction, null); return(RegisterActionAsyncCore(action)); }