private void CreateStateMachineBoxIfNot <TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { if (_stateMachineBox == null) { var stateMachineBox = StateMachineBox <TStateMachine> .Allocate(ref stateMachine); _stateMachineBox = stateMachineBox; } }
void IStateMachineBoxAwareAwaiter.UnsafeOnCompleted(IStateMachineBox box) { var promise = _future.GetPromise(); if (promise != null) { promise.AddContinuation(box); return; } // If promise is null, it means the future was created from a result, // invoke the continuation immediately box.MoveNext(); }
private void ReturnToPool() { if (_token == 0) { throw new ObjectDisposedException(this.GetType().Name); } _token = 0; if (_stateMachineBox != null) { _stateMachineBox.Return(); _stateMachineBox = null; } _status = ValueSourceStatus.Pending; _continuation = null; _continueWithAction = null; _runWithContinue = false; _pool.Push(this); Diagnostics.Trace.TraceReturn(this); }
void IStateMachineBoxAwareAwaiter.UnsafeOnCompleted(IStateMachineBox box) { box.SetScheduler(_scheduler); box.Invoke(); }