A Fiber is a lightweight means of scheduling work that enables multiple units of processing to execute concurrently by co-operatively sharing execution time on a single thread. More...

+ Collaboration diagram for SpicyPixel.Threading.Fiber:

Public Member Functions

Fiber ContinueWith (IEnumerator continuationCoroutine)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (IEnumerator continuationCoroutine, CancellationToken cancellationToken)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (IEnumerator continuationCoroutine, FiberContinuationOptions continuationOptions)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (IEnumerator continuationCoroutine, FiberScheduler scheduler)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (IEnumerator continuationCoroutine, CancellationToken cancellationToken, FiberContinuationOptions continuationOptions, FiberScheduler scheduler)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (Action< Fiber > continuationAction)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (Action< Fiber > continuationAction, CancellationToken cancellationToken)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (Action< Fiber > continuationAction, FiberContinuationOptions continuationOptions)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (Action< Fiber > continuationAction, FiberScheduler scheduler)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (Action< Fiber > continuationAction, CancellationToken cancellationToken, FiberContinuationOptions continuationOptions, FiberScheduler scheduler)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (Action< Fiber, object > continuationAction, object state)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (Action< Fiber, object > continuationAction, object state, CancellationToken cancellationToken)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (Action< Fiber, object > continuationAction, object state, FiberContinuationOptions continuationOptions)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (Action< Fiber, object > continuationAction, object state, FiberScheduler scheduler)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
Fiber ContinueWith (Action< Fiber, object > continuationAction, object state, CancellationToken cancellationToken, FiberContinuationOptions continuationOptions, FiberScheduler scheduler)
 Creates a continuation that executes asynchronously when the target fiber completes. More...
 
 Fiber (IEnumerator coroutine)
 Initializes a new instance of the SpicyPixel.Threading.Fiber class. More...
 
 Fiber (IEnumerator coroutine, CancellationToken cancellationToken)
 Initializes a new instance of the SpicyPixel.Threading.Fiber class. More...
 
 Fiber (Action action)
 Initializes a new instance of the SpicyPixel.Threading.Fiber class. More...
 
 Fiber (Action action, CancellationToken cancellationToken)
 Initializes a new instance of the SpicyPixel.Threading.Fiber class. More...
 
 Fiber (Action< object > action, object state)
 Initializes a new instance of the SpicyPixel.Threading.Fiber class. More...
 
 Fiber (Action< object > action, object state, CancellationToken cancellationToken)
 Initializes a new instance of the SpicyPixel.Threading.Fiber class. More...
 
 Fiber (Func< FiberInstruction > func)
 Initializes a new instance of the SpicyPixel.Threading.Fiber class. More...
 
 Fiber (Func< FiberInstruction > func, CancellationToken cancellationToken)
 Initializes a new instance of the SpicyPixel.Threading.Fiber class. More...
 
 Fiber (Func< object, FiberInstruction > func, object state)
 Initializes a new instance of the SpicyPixel.Threading.Fiber class. More...
 
 Fiber (Func< object, FiberInstruction > func, object state, CancellationToken cancellationToken)
 Initializes a new instance of the SpicyPixel.Threading.Fiber class. More...
 
void Start ()
 Start executing the fiber using the default scheduler on the thread. More...
 
void Start (FiberScheduler scheduler)
 Start executing the fiber using the specified scheduler. More...
 
void ThrowIfCanceled ()
 Throws if canceled. More...
 
void ThrowIfFaulted ()
 Throws if faulted. More...
 
void ThrowIfCanceledOrFaulted ()
 Throws if canceled or faulted. More...
 

Static Public Member Functions

static Fiber Delay (int millisecondsDelay)
 Crates a Fiber that waits for a delay before completing. More...
 
static Fiber Delay (TimeSpan delay)
 Crates a Fiber that waits for a delay before completing. More...
 
static Fiber Delay (TimeSpan delay, CancellationToken cancellationToken)
 Crates a Fiber that waits for a delay before completing. More...
 
static Fiber Delay (int millisecondsDelay, CancellationToken cancellationToken)
 Crates a Fiber that waits for a delay before completing. More...
 
static Fiber Delay (int millisecondsDelay, CancellationToken cancellationToken, FiberScheduler scheduler)
 Crates a Fiber that waits for a delay before completing. More...
 
static Fiber WhenAll (params Fiber [] fibers)
 Returns a fiber that waits on all fibers to complete. More...
 
static Fiber WhenAll (Fiber [] fibers, CancellationToken cancellationToken)
 Returns a fiber that waits on all fibers to complete. More...
 
static Fiber WhenAll (Fiber [] fibers, TimeSpan timeout)
 Returns a fiber that waits on all fibers to complete. More...
 
static Fiber WhenAll (Fiber [] fibers, int millisecondsTimeout)
 Returns a fiber that waits on all fibers to complete. More...
 
static Fiber WhenAll (Fiber [] fibers, int millisecondsTimeout, CancellationToken cancellationToken)
 Returns a fiber that waits on all fibers to complete. More...
 
static Fiber WhenAll (Fiber [] fibers, int millisecondsTimeout, CancellationToken cancellationToken, FiberScheduler scheduler)
 Returns a fiber that waits on all fibers to complete. More...
 
static Fiber WhenAll (IEnumerable< Fiber > fibers, int millisecondsTimeout, CancellationToken cancellationToken, FiberScheduler scheduler)
 Returns a fiber that waits on all fibers to complete. More...
 
static Fiber WhenAll (params Task [] tasks)
 Returns a fiber that waits on all tasks to complete. More...
 
static Fiber WhenAll (Task [] tasks, CancellationToken cancellationToken)
 Returns a fiber that waits on all tasks to complete. More...
 
static Fiber WhenAll (Task [] tasks, TimeSpan timeout)
 Returns a fiber that waits on all tasks to complete. More...
 
static Fiber WhenAll (Task [] tasks, int millisecondsTimeout)
 Returns a fiber that waits on all tasks to complete. More...
 
static Fiber WhenAll (Task [] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
 Returns a fiber that waits on all tasks to complete. More...
 
static Fiber WhenAll (Task [] tasks, int millisecondsTimeout, CancellationToken cancellationToken, FiberScheduler scheduler)
 Returns a fiber that waits on all tasks to complete. More...
 
static Fiber WhenAll (IEnumerable< Task > tasks, int millisecondsTimeout, CancellationToken cancellationToken, FiberScheduler scheduler)
 Returns a fiber that waits on all tasks to complete. More...
 
static Fiber WhenAny (params Fiber[] fibers)
 Returns a fiber that completes when any fiber finishes. More...
 
static Fiber WhenAny (Fiber[] fibers, CancellationToken cancellationToken)
 Returns a fiber that completes when any fiber finishes. More...
 
static Fiber WhenAny (Fiber[] fibers, TimeSpan timeout)
 Returns a fiber that completes when any fiber finishes. More...
 
static Fiber WhenAny (Fiber[] fibers, int millisecondsTimeout)
 Returns a fiber that completes when any fiber finishes. More...
 
static Fiber WhenAny (Fiber[] fibers, int millisecondsTimeout, CancellationToken cancellationToken)
 Returns a fiber that completes when any fiber finishes. More...
 
static Fiber WhenAny (Fiber[] fibers, int millisecondsTimeout, CancellationToken cancellationToken, FiberScheduler scheduler)
 Returns a fiber that completes when any fiber finishes. More...
 
static Fiber WhenAny (IEnumerable< Fiber > fibers, int millisecondsTimeout, CancellationToken cancellationToken, FiberScheduler scheduler)
 Returns a fiber that completes when any fiber finishes. More...
 
static Fiber WhenAny (params Task [] tasks)
 Returns a fiber that completes when any task finishes. More...
 
static Fiber WhenAny (Task [] tasks, CancellationToken cancellationToken)
 Returns a fiber that completes when any task finishes. More...
 
static Fiber WhenAny (Task [] tasks, TimeSpan timeout)
 Returns a fiber that completes when any task finishes. More...
 
static Fiber WhenAny (Task [] tasks, int millisecondsTimeout)
 Returns a fiber that completes when any task finishes. More...
 
static Fiber WhenAny (Task [] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
 Returns a fiber that completes when any task finishes. More...
 
static Fiber WhenAny (Task [] tasks, int millisecondsTimeout, CancellationToken cancellationToken, FiberScheduler scheduler)
 Returns a fiber that completes when any task finishes. More...
 
static Fiber WhenAny (IEnumerable< Task > tasks, int millisecondsTimeout, CancellationToken cancellationToken, FiberScheduler scheduler)
 Returns a fiber that completes when any task finishes. More...
 

Properties

static Fiber CurrentFiber [get]
 Gets the currently executing fiber on this thread. More...
 
static FiberFactory Factory [get]
 Gets the default factory for creating fibers. More...
 
IDictionary< string, object > Properties [get]
 Gets user-defined properties associated with the fiber. More...
 
string Name [get, set]
 Gets or sets the name. More...
 
object ResultAsObject [get, set]
 Gets or sets the result of the fiber's execution as an object. More...
 
bool IsCanceled [get]
 Gets a value indicating whether this instance is canceled. More...
 
bool IsCompleted [get]
 Gets a value indicating whether this instance is completed. More...
 
bool IsFaulted [get]
 Gets a value indicating whether this instance is faulted. More...
 
Exception Exception [get]
 Gets the exception that led to the Faulted state. More...
 
FiberStatus Status [get, set]
 Gets or sets the state of the fiber. More...
 
Fiber Antecedent [get]
 Gets the antecedent, which is the fiber that this fiber was dependent upon for starting execution. More...
 
CancellationToken CancellationToken [get]
 Gets the cancellation token for the Fiber. More...
 
int Id [get]
 Gets the thread unique identifier for the fiber. More...
 

Detailed Description

A Fiber is a lightweight means of scheduling work that enables multiple units of processing to execute concurrently by co-operatively sharing execution time on a single thread.

Fibers are also known as "micro-threads" and can be implemented using programming language facilities such as "coroutines".

Fibers simplify many concurrency issues generally associated with multithreading because a given fiber has complete control over when it yields execution to another fiber. A fiber does not need to manage resource locking or handle changing data in the same way as a thread does because access to a resource is never preempted by another fiber without co-operation.

Fibers can improve performance in certain applications with concurrency requirements. Because many fibers can run on a thread, this can relieve pressure on precious resources in the thread pool and reduce latency. Additionally, some applications have concurrent, interdependent processes that naturally lend themselves to co-operative scheduling which can result in greater efficiency when the application manages the context switch instead of a pre-emptive scheduler.

Fibers can also be a convenient way to express a state machine. The master fiber implementing the machine can test state conditions, start new fibers for state actions, yield to an action fiber until it completes, and then handle the transition out of the state and into a new state.

Definition at line 8 of file Fiber.ContinueWith.cs.

Constructor & Destructor Documentation

◆ Fiber() [1/10]

SpicyPixel.Threading.Fiber.Fiber ( IEnumerator  coroutine)

Initializes a new instance of the SpicyPixel.Threading.Fiber class.

Parameters
coroutineA couroutine to execute on the fiber.

Definition at line 323 of file Fiber.cs.

◆ Fiber() [2/10]

SpicyPixel.Threading.Fiber.Fiber ( IEnumerator  coroutine,
CancellationToken  cancellationToken 
)

Initializes a new instance of the SpicyPixel.Threading.Fiber class.

Parameters
coroutineA couroutine to execute on the fiber.
cancellationTokenCancellation token.

Definition at line 334 of file Fiber.cs.

◆ Fiber() [3/10]

SpicyPixel.Threading.Fiber.Fiber ( Action  action)

Initializes a new instance of the SpicyPixel.Threading.Fiber class.

Parameters
actionA non-blocking action to execute on the fiber.

Definition at line 347 of file Fiber.cs.

◆ Fiber() [4/10]

SpicyPixel.Threading.Fiber.Fiber ( Action  action,
CancellationToken  cancellationToken 
)

Initializes a new instance of the SpicyPixel.Threading.Fiber class.

Parameters
actionA non-blocking action to execute on the fiber.
cancellationTokenCancellation token.

Definition at line 358 of file Fiber.cs.

◆ Fiber() [5/10]

SpicyPixel.Threading.Fiber.Fiber ( Action< object >  action,
object  state 
)

Initializes a new instance of the SpicyPixel.Threading.Fiber class.

Parameters
actionA non-blocking action to execute on the fiber.
stateState to pass to the action.

Definition at line 374 of file Fiber.cs.

◆ Fiber() [6/10]

SpicyPixel.Threading.Fiber.Fiber ( Action< object >  action,
object  state,
CancellationToken  cancellationToken 
)

Initializes a new instance of the SpicyPixel.Threading.Fiber class.

Parameters
actionA non-blocking action to execute on the fiber.
stateState to pass to the action.
cancellationTokenCancellation token.

Definition at line 388 of file Fiber.cs.

◆ Fiber() [7/10]

SpicyPixel.Threading.Fiber.Fiber ( Func< FiberInstruction func)

Initializes a new instance of the SpicyPixel.Threading.Fiber class.

Parameters
funcA non-blocking function that returns a FiberInstruction when complete.

Definition at line 402 of file Fiber.cs.

◆ Fiber() [8/10]

SpicyPixel.Threading.Fiber.Fiber ( Func< FiberInstruction func,
CancellationToken  cancellationToken 
)

Initializes a new instance of the SpicyPixel.Threading.Fiber class.

Parameters
funcA non-blocking function that returns a FiberInstruction when complete.
cancellationTokenCancellation token.

Definition at line 413 of file Fiber.cs.

◆ Fiber() [9/10]

SpicyPixel.Threading.Fiber.Fiber ( Func< object, FiberInstruction func,
object  state 
)

Initializes a new instance of the SpicyPixel.Threading.Fiber class.

Parameters
funcA non-blocking function that returns a FiberInstruction when complete.
stateState to pass to the function.

Definition at line 429 of file Fiber.cs.

◆ Fiber() [10/10]

SpicyPixel.Threading.Fiber.Fiber ( Func< object, FiberInstruction func,
object  state,
CancellationToken  cancellationToken 
)

Initializes a new instance of the SpicyPixel.Threading.Fiber class.

Parameters
funcA non-blocking function that returns a FiberInstruction when complete.
stateState to pass to the function.
cancellationTokenCancellation token.

Definition at line 443 of file Fiber.cs.

Member Function Documentation

◆ ContinueWith() [1/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( IEnumerator  continuationCoroutine)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationCoroutineContinuation coroutine.

Definition at line 15 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [2/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( IEnumerator  continuationCoroutine,
CancellationToken  cancellationToken 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationCoroutineContinuation coroutine.
cancellationTokenCancellation token.

Definition at line 26 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [3/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( IEnumerator  continuationCoroutine,
FiberContinuationOptions  continuationOptions 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationCoroutineContinuation coroutine.
continuationOptionsContinuation options.

Definition at line 37 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [4/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( IEnumerator  continuationCoroutine,
FiberScheduler  scheduler 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationCoroutineContinuation coroutine.
schedulerScheduler.

Definition at line 48 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [5/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( IEnumerator  continuationCoroutine,
CancellationToken  cancellationToken,
FiberContinuationOptions  continuationOptions,
FiberScheduler  scheduler 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationCoroutineContinuation coroutine.
cancellationTokenCancellation token.
continuationOptionsContinuation options.
schedulerScheduler.

Definition at line 61 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [6/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( Action< Fiber continuationAction)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationActionContinuation action.

Definition at line 95 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [7/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( Action< Fiber continuationAction,
CancellationToken  cancellationToken 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationActionContinuation action.
cancellationTokenCancellation token.

Definition at line 106 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [8/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( Action< Fiber continuationAction,
FiberContinuationOptions  continuationOptions 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationActionContinuation action.
continuationOptionsContinuation options.

Definition at line 117 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [9/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( Action< Fiber continuationAction,
FiberScheduler  scheduler 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationActionContinuation action.
schedulerScheduler.

Definition at line 128 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [10/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( Action< Fiber continuationAction,
CancellationToken  cancellationToken,
FiberContinuationOptions  continuationOptions,
FiberScheduler  scheduler 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationActionContinuation action.
cancellationTokenCancellation token.
continuationOptionsContinuation options.
schedulerScheduler.

Definition at line 141 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [11/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( Action< Fiber, object >  continuationAction,
object  state 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationActionContinuation action.
stateState.

Definition at line 153 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [12/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( Action< Fiber, object >  continuationAction,
object  state,
CancellationToken  cancellationToken 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationActionContinuation action.
stateState.
cancellationTokenCancellation token.

Definition at line 165 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [13/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( Action< Fiber, object >  continuationAction,
object  state,
FiberContinuationOptions  continuationOptions 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationActionContinuation action.
stateState.
continuationOptionsContinuation options.

Definition at line 177 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [14/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( Action< Fiber, object >  continuationAction,
object  state,
FiberScheduler  scheduler 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationActionContinuation action.
stateState.
schedulerScheduler.

Definition at line 189 of file Fiber.ContinueWith.cs.

◆ ContinueWith() [15/15]

Fiber SpicyPixel.Threading.Fiber.ContinueWith ( Action< Fiber, object >  continuationAction,
object  state,
CancellationToken  cancellationToken,
FiberContinuationOptions  continuationOptions,
FiberScheduler  scheduler 
)

Creates a continuation that executes asynchronously when the target fiber completes.

Returns
A fiber that executes when the target fiber completes.
Parameters
continuationActionContinuation action.
stateState.
cancellationTokenCancellation token.
continuationOptionsContinuation options.
schedulerScheduler.

Definition at line 203 of file Fiber.ContinueWith.cs.

◆ Delay() [1/5]

static Fiber SpicyPixel.Threading.Fiber.Delay ( int  millisecondsDelay)
static

Crates a Fiber that waits for a delay before completing.

Parameters
millisecondsDelayMilliseconds to delay.

Definition at line 13 of file Fiber.Delay.cs.

◆ Delay() [2/5]

static Fiber SpicyPixel.Threading.Fiber.Delay ( TimeSpan  delay)
static

Crates a Fiber that waits for a delay before completing.

Parameters
delayTime span to delay.

Definition at line 22 of file Fiber.Delay.cs.

◆ Delay() [3/5]

static Fiber SpicyPixel.Threading.Fiber.Delay ( TimeSpan  delay,
CancellationToken  cancellationToken 
)
static

Crates a Fiber that waits for a delay before completing.

Parameters
delayTime span to delay.
cancellationTokenCancellation token.

Definition at line 32 of file Fiber.Delay.cs.

◆ Delay() [4/5]

static Fiber SpicyPixel.Threading.Fiber.Delay ( int  millisecondsDelay,
CancellationToken  cancellationToken 
)
static

Crates a Fiber that waits for a delay before completing.

Parameters
millisecondsDelayMilliseconds to delay.
cancellationTokenCancellation token.

Definition at line 42 of file Fiber.Delay.cs.

◆ Delay() [5/5]

static Fiber SpicyPixel.Threading.Fiber.Delay ( int  millisecondsDelay,
CancellationToken  cancellationToken,
FiberScheduler  scheduler 
)
static

Crates a Fiber that waits for a delay before completing.

Parameters
millisecondsDelayMilliseconds to delay.
cancellationTokenCancellation token.
schedulerScheduler.

Definition at line 53 of file Fiber.Delay.cs.

◆ Start() [1/2]

void SpicyPixel.Threading.Fiber.Start ( )

Start executing the fiber using the default scheduler on the thread.

Definition at line 454 of file Fiber.cs.

◆ Start() [2/2]

void SpicyPixel.Threading.Fiber.Start ( FiberScheduler  scheduler)

Start executing the fiber using the specified scheduler.

This method is safe to call from any thread even if different than the scheduler execution thread.

Parameters
schedulerThe scheduler to start the fiber on.

Definition at line 469 of file Fiber.cs.

◆ ThrowIfCanceled()

void SpicyPixel.Threading.Fiber.ThrowIfCanceled ( )

Throws if canceled.

Definition at line 490 of file Fiber.cs.

◆ ThrowIfCanceledOrFaulted()

void SpicyPixel.Threading.Fiber.ThrowIfCanceledOrFaulted ( )

Throws if canceled or faulted.

Definition at line 508 of file Fiber.cs.

◆ ThrowIfFaulted()

void SpicyPixel.Threading.Fiber.ThrowIfFaulted ( )

Throws if faulted.

Definition at line 499 of file Fiber.cs.

◆ WhenAll() [1/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( params Fiber []  fibers)
static

Returns a fiber that waits on all fibers to complete.

Fiber.ResultAsObject will be true if all fibers complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all fibers to complete.
Parameters
fibersFibers to wait for completion.

Definition at line 21 of file Fiber.WhenAll.cs.

◆ WhenAll() [2/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( Fiber []  fibers,
CancellationToken  cancellationToken 
)
static

Returns a fiber that waits on all fibers to complete.

Fiber.ResultAsObject will be true if all fibers complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all fibers to complete.
Parameters
fibersFibers to wait for completion.
cancellationTokenCancellation token.

Definition at line 36 of file Fiber.WhenAll.cs.

◆ WhenAll() [3/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( Fiber []  fibers,
TimeSpan  timeout 
)
static

Returns a fiber that waits on all fibers to complete.

Fiber.ResultAsObject will be true if all fibers complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all fibers to complete.
Parameters
fibersFibers to wait for completion.
timeoutTimeout.

Definition at line 51 of file Fiber.WhenAll.cs.

◆ WhenAll() [4/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( Fiber []  fibers,
int  millisecondsTimeout 
)
static

Returns a fiber that waits on all fibers to complete.

Fiber.ResultAsObject will be true if all fibers complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all fibers to complete.
Parameters
fibersFibers to wait for completion.
millisecondsTimeoutMilliseconds timeout.

Definition at line 66 of file Fiber.WhenAll.cs.

◆ WhenAll() [5/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( Fiber []  fibers,
int  millisecondsTimeout,
CancellationToken  cancellationToken 
)
static

Returns a fiber that waits on all fibers to complete.

Fiber.ResultAsObject will be true if all fibers complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all fibers to complete.
Parameters
fibersFibers to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.

Definition at line 82 of file Fiber.WhenAll.cs.

◆ WhenAll() [6/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( Fiber []  fibers,
int  millisecondsTimeout,
CancellationToken  cancellationToken,
FiberScheduler  scheduler 
)
static

Returns a fiber that waits on all fibers to complete.

Fiber.ResultAsObject will be true if all fibers complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all fibers to complete.
Parameters
fibersFibers to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.
schedulerScheduler.

Definition at line 99 of file Fiber.WhenAll.cs.

◆ WhenAll() [7/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( IEnumerable< Fiber fibers,
int  millisecondsTimeout,
CancellationToken  cancellationToken,
FiberScheduler  scheduler 
)
static

Returns a fiber that waits on all fibers to complete.

Fiber.ResultAsObject will be true if all fibers complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all fibers to complete.
Parameters
fibersFibers to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.
schedulerScheduler.

Definition at line 124 of file Fiber.WhenAll.cs.

◆ WhenAll() [8/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( params Task []  tasks)
static

Returns a fiber that waits on all tasks to complete.

Fiber.ResultAsObject will be true if all tasks complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all tasks to complete.
Parameters
tasksTasks to wait for completion.

Definition at line 164 of file Fiber.WhenAll.cs.

◆ WhenAll() [9/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( Task []  tasks,
CancellationToken  cancellationToken 
)
static

Returns a fiber that waits on all tasks to complete.

Fiber.ResultAsObject will be true if all tasks complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all tasks to complete.
Parameters
tasksTasks to wait for completion.
cancellationTokenCancellation token.

Definition at line 179 of file Fiber.WhenAll.cs.

◆ WhenAll() [10/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( Task []  tasks,
TimeSpan  timeout 
)
static

Returns a fiber that waits on all tasks to complete.

Fiber.ResultAsObject will be true if all tasks complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all tasks to complete.
Parameters
tasksTasks to wait for completion.
timeoutTimeout.

Definition at line 194 of file Fiber.WhenAll.cs.

◆ WhenAll() [11/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( Task []  tasks,
int  millisecondsTimeout 
)
static

Returns a fiber that waits on all tasks to complete.

Fiber.ResultAsObject will be true if all tasks complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all tasks to complete.
Parameters
tasksTasks to wait for completion.
millisecondsTimeoutMilliseconds timeout.

Definition at line 209 of file Fiber.WhenAll.cs.

◆ WhenAll() [12/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( Task []  tasks,
int  millisecondsTimeout,
CancellationToken  cancellationToken 
)
static

Returns a fiber that waits on all tasks to complete.

Fiber.ResultAsObject will be true if all tasks complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all tasks to complete.
Parameters
tasksTasks to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.

Definition at line 225 of file Fiber.WhenAll.cs.

◆ WhenAll() [13/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( Task []  tasks,
int  millisecondsTimeout,
CancellationToken  cancellationToken,
FiberScheduler  scheduler 
)
static

Returns a fiber that waits on all tasks to complete.

Fiber.ResultAsObject will be true if all tasks complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all tasks to complete.
Parameters
tasksTasks to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.
schedulerScheduler.

Definition at line 242 of file Fiber.WhenAll.cs.

◆ WhenAll() [14/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAll ( IEnumerable< Task tasks,
int  millisecondsTimeout,
CancellationToken  cancellationToken,
FiberScheduler  scheduler 
)
static

Returns a fiber that waits on all tasks to complete.

Fiber.ResultAsObject will be true if all tasks complete successfully or false if cancelled or timeout.

Returns
A fiber that waits on all tasks to complete.
Parameters
tasksTasks to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.
schedulerScheduler.

Definition at line 267 of file Fiber.WhenAll.cs.

◆ WhenAny() [1/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( params Fiber []  fibers)
static

Returns a fiber that completes when any fiber finishes.

Fiber.ResultAsObject will be the Fiber that completed.

Returns
A fiber that completes when any fiber finishes.
Parameters
fibersFibers to wait for completion.

Definition at line 20 of file Fiber.WhenAny.cs.

◆ WhenAny() [2/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( Fiber []  fibers,
CancellationToken  cancellationToken 
)
static

Returns a fiber that completes when any fiber finishes.

Fiber.ResultAsObject will be the Fiber that completed.

Returns
A fiber that completes when any fiber finishes.
Parameters
fibersFibers to wait for completion.
cancellationTokenCancellation token.

Definition at line 34 of file Fiber.WhenAny.cs.

◆ WhenAny() [3/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( Fiber []  fibers,
TimeSpan  timeout 
)
static

Returns a fiber that completes when any fiber finishes.

Fiber.ResultAsObject will be the Fiber that completed.

Returns
A fiber that completes when any fiber finishes.
Parameters
fibersFibers to wait for completion.
timeoutTimeout.

Definition at line 48 of file Fiber.WhenAny.cs.

◆ WhenAny() [4/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( Fiber []  fibers,
int  millisecondsTimeout 
)
static

Returns a fiber that completes when any fiber finishes.

Fiber.ResultAsObject will be the Fiber that completed.

Returns
A fiber that completes when any fiber finishes.
Parameters
fibersFibers to wait for completion.
millisecondsTimeoutMilliseconds timeout.

Definition at line 62 of file Fiber.WhenAny.cs.

◆ WhenAny() [5/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( Fiber []  fibers,
int  millisecondsTimeout,
CancellationToken  cancellationToken 
)
static

Returns a fiber that completes when any fiber finishes.

Fiber.ResultAsObject will be the Fiber that completed.

Returns
A fiber that completes when any fiber finishes.
Parameters
fibersFibers to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.

Definition at line 77 of file Fiber.WhenAny.cs.

◆ WhenAny() [6/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( Fiber []  fibers,
int  millisecondsTimeout,
CancellationToken  cancellationToken,
FiberScheduler  scheduler 
)
static

Returns a fiber that completes when any fiber finishes.

Fiber.ResultAsObject will be the Fiber that completed.

Returns
A fiber that completes when any fiber finishes.
Parameters
fibersFibers to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.
schedulerScheduler.

Definition at line 93 of file Fiber.WhenAny.cs.

◆ WhenAny() [7/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( IEnumerable< Fiber fibers,
int  millisecondsTimeout,
CancellationToken  cancellationToken,
FiberScheduler  scheduler 
)
static

Returns a fiber that completes when any fiber finishes.

Fiber.ResultAsObject will be the Fiber that completed.

Returns
A fiber that completes when any fiber finishes.
Parameters
fibersFibers to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.
schedulerScheduler.

Definition at line 117 of file Fiber.WhenAny.cs.

◆ WhenAny() [8/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( params Task []  tasks)
static

Returns a fiber that completes when any task finishes.

Fiber.ResultAsObject will be the Task that completed.

Returns
A fiber that completes when any task finishes.
Parameters
tasksTasks to wait for completion.

Definition at line 150 of file Fiber.WhenAny.cs.

◆ WhenAny() [9/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( Task []  tasks,
CancellationToken  cancellationToken 
)
static

Returns a fiber that completes when any task finishes.

Fiber.ResultAsObject will be the Task that completed.

Returns
A fiber that completes when any task finishes.
Parameters
tasksTasks to wait for completion.
cancellationTokenCancellation token.

Definition at line 164 of file Fiber.WhenAny.cs.

◆ WhenAny() [10/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( Task []  tasks,
TimeSpan  timeout 
)
static

Returns a fiber that completes when any task finishes.

Fiber.ResultAsObject will be the Task that completed.

Returns
A fiber that completes when any task finishes.
Parameters
tasksTasks to wait for completion.
timeoutTimeout.

Definition at line 178 of file Fiber.WhenAny.cs.

◆ WhenAny() [11/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( Task []  tasks,
int  millisecondsTimeout 
)
static

Returns a fiber that completes when any task finishes.

Fiber.ResultAsObject will be the Task that completed.

Returns
A fiber that completes when any task finishes.
Parameters
tasksTasks to wait for completion.
millisecondsTimeoutMilliseconds timeout.

Definition at line 192 of file Fiber.WhenAny.cs.

◆ WhenAny() [12/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( Task []  tasks,
int  millisecondsTimeout,
CancellationToken  cancellationToken 
)
static

Returns a fiber that completes when any task finishes.

Fiber.ResultAsObject will be the Task that completed.

Returns
A fiber that completes when any task finishes.
Parameters
tasksTasks to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.

Definition at line 207 of file Fiber.WhenAny.cs.

◆ WhenAny() [13/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( Task []  tasks,
int  millisecondsTimeout,
CancellationToken  cancellationToken,
FiberScheduler  scheduler 
)
static

Returns a fiber that completes when any task finishes.

Fiber.ResultAsObject will be the Task that completed.

Returns
A fiber that completes when any task finishes.
Parameters
tasksTasks to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.
schedulerScheduler.

Definition at line 223 of file Fiber.WhenAny.cs.

◆ WhenAny() [14/14]

static Fiber SpicyPixel.Threading.Fiber.WhenAny ( IEnumerable< Task tasks,
int  millisecondsTimeout,
CancellationToken  cancellationToken,
FiberScheduler  scheduler 
)
static

Returns a fiber that completes when any task finishes.

Fiber.ResultAsObject will be the Task that completed.

Returns
A fiber that completes when any task finishes.
Parameters
tasksTasks to wait for completion.
millisecondsTimeoutMilliseconds timeout.
cancellationTokenCancellation token.
schedulerScheduler.

Definition at line 247 of file Fiber.WhenAny.cs.

Property Documentation

◆ Antecedent

Fiber SpicyPixel.Threading.Fiber.Antecedent
get

Gets the antecedent, which is the fiber that this fiber was dependent upon for starting execution.

The antecedent provides access to a prior result through GetAsResultObject().

The antecedent.

Definition at line 250 of file Fiber.cs.

◆ CancellationToken

CancellationToken SpicyPixel.Threading.Fiber.CancellationToken
get

Gets the cancellation token for the Fiber.

The token is made available because coroutines don't have a convenient way to get at it otherwise. This way, an executing coroutine can:

Fiber.CurrentFiber.CancellationToken.ThrowIfCancellationRequested();

The cancellation token.

Definition at line 266 of file Fiber.cs.

◆ CurrentFiber

Fiber SpicyPixel.Threading.Fiber.CurrentFiber
staticget

Gets the currently executing fiber on this thread.

The currently executing fiber on this thread.

Definition at line 106 of file Fiber.cs.

◆ Exception

Exception SpicyPixel.Threading.Fiber.Exception
get

Gets the exception that led to the Faulted state.

The exception.

Definition at line 226 of file Fiber.cs.

◆ Factory

FiberFactory SpicyPixel.Threading.Fiber.Factory
staticget

Gets the default factory for creating fibers.

The factory.

Definition at line 119 of file Fiber.cs.

◆ Id

int SpicyPixel.Threading.Fiber.Id
get

Gets the thread unique identifier for the fiber.

The identifier.

Definition at line 315 of file Fiber.cs.

◆ IsCanceled

bool SpicyPixel.Threading.Fiber.IsCanceled
get

Gets a value indicating whether this instance is canceled.

true if this instance is canceled; otherwise, false.

Definition at line 187 of file Fiber.cs.

◆ IsCompleted

bool SpicyPixel.Threading.Fiber.IsCompleted
get

Gets a value indicating whether this instance is completed.

"Completed" means:

true if this instance is completed; otherwise, false.

Definition at line 203 of file Fiber.cs.

◆ IsFaulted

bool SpicyPixel.Threading.Fiber.IsFaulted
get

Gets a value indicating whether this instance is faulted.

See Fiber.Exception for the exception causing the fault.

true if this instance is faulted; otherwise, false.

Definition at line 216 of file Fiber.cs.

◆ Name

string SpicyPixel.Threading.Fiber.Name
getset

Gets or sets the name.

The name.

Definition at line 175 of file Fiber.cs.

◆ Properties

IDictionary<string, object> SpicyPixel.Threading.Fiber.Properties
get

Gets user-defined properties associated with the fiber.

Similar to thread local storage, callers may associate data with a fiber. A FiberStorage<T> class could retrieve data from the this property collection on the CurrentFiber.

Schedulers may also use this storage to associate additional data needed to perform scheduling operations.

The properties.

Definition at line 149 of file Fiber.cs.

◆ ResultAsObject

object SpicyPixel.Threading.Fiber.ResultAsObject
getset

Gets or sets the result of the fiber's execution as an object.

The result of the fiber's execution as an object.

Definition at line 181 of file Fiber.cs.

◆ Status

FiberStatus SpicyPixel.Threading.Fiber.Status
getset

Gets or sets the state of the fiber.

The state of the fiber (Unstarted, Running, Stopped).

Definition at line 237 of file Fiber.cs.


The documentation for this class was generated from the following files: