/// <summary> /// Creates a re-entrant function that waits for sync points in sequence. /// </summary> /// <param name="count">The number of sync points to expect</param> /// <param name="syncPoints">The <see cref="SyncPoint"/> objects that can be used to coordinate the sync point</param> /// <returns></returns> public static Func <Task> Create(int count, out SyncPoint[] syncPoints, bool runContinuationsAsynchronously = true) { // Need to use a local so the closure can capture it. You can't use out vars in a closure. var localSyncPoints = new SyncPoint[count]; for (var i = 0; i < count; i += 1) { localSyncPoints[i] = new SyncPoint(runContinuationsAsynchronously); } syncPoints = localSyncPoints; var counter = 0; return(() => { if (counter >= localSyncPoints.Length) { return Task.CompletedTask; } else { var syncPoint = localSyncPoints[counter]; counter += 1; return syncPoint.WaitToContinue(); } }); }
public static Func <Task> Create(out SyncPoint syncPoint, bool runContinuationsAsynchronously = true) { var handler = Create(1, out var syncPoints, runContinuationsAsynchronously); syncPoint = syncPoints[0]; return(handler); }
public SyncPointMemoryStream(bool runContinuationsAsynchronously = true) { _runContinuationsAsynchronously = runContinuationsAsynchronously; _currentData = Array.Empty <byte>(); _awaiter = SyncPoint.Create(out _syncPoint, _runContinuationsAsynchronously); }
private void ResetSyncPoint() { _awaiter = SyncPoint.Create(out _syncPoint, _runContinuationsAsynchronously); }
public SyncPointMemoryStream() { _currentData = Array.Empty <byte>(); _awaiter = SyncPoint.Create(out _syncPoint); }
private void ResetSyncPoint() { _awaiter = SyncPoint.Create(out _syncPoint); }