internal static void CheckContinuationOptions(FiberContinuationOptions continuationOptions) { if ((continuationOptions & (FiberContinuationOptions.OnlyOnRanToCompletion | FiberContinuationOptions.NotOnRanToCompletion)) != 0) { throw new ArgumentOutOfRangeException("continuationOptions"); } }
bool ContinuationStateCheck(FiberContinuationOptions options) { if (options == FiberContinuationOptions.None) return true; int optionCode = (int) options; var status = fiber.antecedent.Status; if (optionCode >= ((int) FiberContinuationOptions.NotOnRanToCompletion)) { if (status == FiberStatus.Canceled) { if (options == FiberContinuationOptions.NotOnCanceled) return false; if (options == FiberContinuationOptions.OnlyOnFaulted) return false; if (options == FiberContinuationOptions.OnlyOnRanToCompletion) return false; } else if (status == FiberStatus.Faulted) { if (options == FiberContinuationOptions.NotOnFaulted) return false; if (options == FiberContinuationOptions.OnlyOnCanceled) return false; if (options == FiberContinuationOptions.OnlyOnRanToCompletion) return false; } else if (status == FiberStatus.RanToCompletion) { if (options == FiberContinuationOptions.NotOnRanToCompletion) return false; if (options == FiberContinuationOptions.OnlyOnFaulted) return false; if (options == FiberContinuationOptions.OnlyOnCanceled) return false; } } return true; }
/// <summary> /// Creates a continuation that executes asynchronously when the target fiber completes. /// </summary> /// <returns>A fiber that executes when the target fiber completes.</returns> /// <param name="continuationCoroutine">Continuation coroutine.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <param name="continuationOptions">Continuation options.</param> /// <param name="scheduler">Scheduler.</param> public Fiber ContinueWith(IEnumerator continuationCoroutine, CancellationToken cancellationToken, FiberContinuationOptions continuationOptions, FiberScheduler scheduler) { if (continuationCoroutine == null) throw new ArgumentNullException("continuationCoroutine"); if (scheduler == null) throw new ArgumentNullException("scheduler"); var fiber = new Fiber(continuationCoroutine, cancellationToken); fiber.antecedent = this; fiber.status = (int)FiberStatus.WaitingForActivation; var continuation = new FiberContinuation(fiber, continuationOptions, scheduler); if (IsCompleted) { continuation.Execute(); } else { // Lazy create queue if (continuations == null) continuations = new Queue<FiberContinuation>(); continuations.Enqueue(continuation); } return fiber; }
/// <summary> /// Initializes a new instance of the <see cref="SpicyPixel.Threading.FiberFactory"/> class. /// </summary> /// <param name="cancellationToken">Cancellation token.</param> /// <param name="continuationOptions">Continuation options.</param> /// <param name="scheduler">Scheduler.</param> public FiberFactory(CancellationToken cancellationToken, FiberContinuationOptions continuationOptions, FiberScheduler scheduler) { this.cancellationToken = cancellationToken; this.continuationOptions = continuationOptions; this.scheduler = scheduler; CheckContinuationOptions(continuationOptions); }
/// <summary> /// Initializes a new instance of the <see cref="SpicyPixel.Threading.FiberFactory"/> class. /// </summary> /// <param name="cancellationToken">Cancellation token.</param> /// <param name="continuationOptions">Continuation options.</param> /// <param name="scheduler">Scheduler.</param> public FiberFactory(CancellationToken cancellationToken, FiberContinuationOptions continuationOptions, FiberScheduler scheduler) { this.cancellationToken = cancellationToken; this.continuationOptions = continuationOptions; this.scheduler = scheduler; CheckContinuationOptions (continuationOptions); }
/// <summary> /// Creates a continuation that executes asynchronously when the target fiber completes. /// </summary> /// <returns>A fiber that executes when the target fiber completes.</returns> /// <param name="continuationAction">Continuation action.</param> /// <param name="state">State.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <param name="continuationOptions">Continuation options.</param> /// <param name="scheduler">Scheduler.</param> public Fiber ContinueWith(Action <Fiber, object> continuationAction, object state, CancellationToken cancellationToken, FiberContinuationOptions continuationOptions, FiberScheduler scheduler) { if (continuationAction == null) { throw new ArgumentNullException("continuationAction"); } if (scheduler == null) { throw new ArgumentNullException("scheduler"); } var fiber = new Fiber((obj) => continuationAction(this, obj), state, cancellationToken); fiber.antecedent = this; fiber.status = (int)FiberStatus.WaitingForActivation; var continuation = new FiberContinuation(fiber, continuationOptions, scheduler); if (IsCompleted) { continuation.Execute(); } else { // Lazy create queue if (continuations == null) { continuations = new Queue <FiberContinuation>(); } continuations.Enqueue(continuation); } return(fiber); }
/// <summary> /// Creates a continuation that executes asynchronously when the target fiber completes. /// </summary> /// <returns>A fiber that executes when the target fiber completes.</returns> /// <param name="continuationAction">Continuation action.</param> /// <param name="state">State.</param> /// <param name="continuationOptions">Continuation options.</param> public Fiber ContinueWith(Action<Fiber, object> continuationAction, object state, FiberContinuationOptions continuationOptions) { return ContinueWith(continuationAction, state, CancellationToken.None, continuationOptions, FiberScheduler.Current); }
/// <summary> /// Creates a continuation that executes asynchronously when the target fiber completes. /// </summary> /// <returns>A fiber that executes when the target fiber completes.</returns> /// <param name="continuationAction">Continuation action.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <param name="continuationOptions">Continuation options.</param> /// <param name="scheduler">Scheduler.</param> public Fiber ContinueWith(Action<Fiber> continuationAction, CancellationToken cancellationToken, FiberContinuationOptions continuationOptions, FiberScheduler scheduler) { return ContinueWith((fiber, state) => continuationAction(fiber), null, cancellationToken, continuationOptions, scheduler); }
bool ContinuationStateCheck(FiberContinuationOptions options) { if (options == FiberContinuationOptions.None) { return(true); } int optionCode = (int)options; var status = fiber.antecedent.Status; if (optionCode >= ((int)FiberContinuationOptions.NotOnRanToCompletion)) { if (status == FiberStatus.Canceled) { if (options == FiberContinuationOptions.NotOnCanceled) { return(false); } if (options == FiberContinuationOptions.OnlyOnFaulted) { return(false); } if (options == FiberContinuationOptions.OnlyOnRanToCompletion) { return(false); } } else if (status == FiberStatus.Faulted) { if (options == FiberContinuationOptions.NotOnFaulted) { return(false); } if (options == FiberContinuationOptions.OnlyOnCanceled) { return(false); } if (options == FiberContinuationOptions.OnlyOnRanToCompletion) { return(false); } } else if (status == FiberStatus.RanToCompletion) { if (options == FiberContinuationOptions.NotOnRanToCompletion) { return(false); } if (options == FiberContinuationOptions.OnlyOnFaulted) { return(false); } if (options == FiberContinuationOptions.OnlyOnCanceled) { return(false); } } } return(true); }
public FiberContinuation(Fiber fiber, FiberContinuationOptions options, FiberScheduler scheduler) { this.fiber = fiber; this.options = options; this.scheduler = scheduler; }
/// <summary> /// Creates a continuation that executes asynchronously when the target fiber completes. /// </summary> /// <returns>A fiber that executes when the target fiber completes.</returns> /// <param name="continuationAction">Continuation action.</param> /// <param name="state">State.</param> /// <param name="continuationOptions">Continuation options.</param> public Fiber ContinueWith(Action <Fiber, object> continuationAction, object state, FiberContinuationOptions continuationOptions) { return(ContinueWith(continuationAction, state, CancellationToken.None, continuationOptions, FiberScheduler.Current)); }
/// <summary> /// Initializes a new instance of the <see cref="SpicyPixel.Threading.FiberFactory"/> class. /// </summary> /// <param name="continuationOptions">Continuation options.</param> public FiberFactory(FiberContinuationOptions continuationOptions) : this(CancellationToken.None, continuationOptions, null) { }
internal static void CheckContinuationOptions(FiberContinuationOptions continuationOptions) { if ((continuationOptions & (FiberContinuationOptions.OnlyOnRanToCompletion | FiberContinuationOptions.NotOnRanToCompletion)) != 0) throw new ArgumentOutOfRangeException ("continuationOptions"); }
/// <summary> /// Creates a continuation that executes asynchronously when the target fiber completes. /// </summary> /// <returns>A fiber that executes when the target fiber completes.</returns> /// <param name="continuationCoroutine">Continuation coroutine.</param> /// <param name="continuationOptions">Continuation options.</param> public Fiber ContinueWith(IEnumerator continuationCoroutine, FiberContinuationOptions continuationOptions) { return(ContinueWith(continuationCoroutine, CancellationToken.None, continuationOptions, FiberScheduler.Current)); }
/// <summary> /// Creates a continuation that executes asynchronously when the target fiber completes. /// </summary> /// <returns>A fiber that executes when the target fiber completes.</returns> /// <param name="continuationCoroutine">Continuation coroutine.</param> /// <param name="continuationOptions">Continuation options.</param> public Fiber ContinueWith(IEnumerator continuationCoroutine, FiberContinuationOptions continuationOptions) { return ContinueWith(continuationCoroutine, CancellationToken.None, continuationOptions, FiberScheduler.Current); }
/// <summary> /// Creates a continuation that executes asynchronously when the target fiber completes. /// </summary> /// <returns>A fiber that executes when the target fiber completes.</returns> /// <param name="continuationAction">Continuation action.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <param name="continuationOptions">Continuation options.</param> /// <param name="scheduler">Scheduler.</param> public Fiber ContinueWith(Action <Fiber> continuationAction, CancellationToken cancellationToken, FiberContinuationOptions continuationOptions, FiberScheduler scheduler) { return(ContinueWith((fiber, state) => continuationAction(fiber), null, cancellationToken, continuationOptions, scheduler)); }