Fiber
Fibers Lighweight Cooperative Multitasking
Askowl.Fiber Class Reference

lightweight cooperative multi-tasking More...

Inheritance diagram for Askowl.Fiber:

Classes

class  Closure
 Closure super-class that does all the smarts More...
 
interface  IClosure
 Interface used by WaitFor(IClosure) More...
 
class  Queue
 Container for different update queues
 
class  Worker
 Abstract code to implement a worker More...
 
class  Worker
 Worker with payload More...
 

Public Member Functions

delegate void Action (Fiber fiber)
 Method signature for Do(Action) methods More...
 
void Dispose ()
 Cleans up Fiber before it goes into the recycling More...
 
Fiber Go ()
 Start a fiber if it is not already running More...
 
Fiber Go (Action updater)
 Start a fiber if it is not already running More...
 
Fiber WaitFor (IClosure closure)
 Helper that is the same as fiber.WaitFor(closure.OnComplete) More...
 
Context< T > ()
 Retrieve the context as a class type - null for none or wrong type More...
 
Fiber Context< T > (T value)
 Set the context to an instance of a type More...
 
Context< T > (string name)
 Retrieve the context as a class type - null for none or wrong type More...
 
Fiber Context< T > (string name, T value)
 Set the context to an instance of a type More...
 
Fiber Exit ()
 Abort fiber processing immediately, cleaning up as we go More...
 
Fiber Exit (Fiber fiber)
 Force another fiber to exit immediately More...
 
void Finish ()
 Complete a Fiber.Start statement where needed (no action) More...
 
Fiber Repeat (int count)
 Begin/Repeat loop for a specific number of times More...
 
Fiber Until (Func< Fiber, bool > isTrue)
 Loop until a value function returns true More...
 
Fiber BreakIf (Func< Fiber, bool > isBreak)
 Break out of any block if a value function returns true More...
 
void Break ()
 Break a Begin/End/Repeat/Again block More...
 
void Break (int after)
 
void Skip (int after)
 
Fiber If (Func< Fiber, bool > isTrue)
 Standard If // Else // Then branch More...
 
Fiber Do (Action nextAction, string name=null)
 Business logic activation step More...
 
IEnumerator AsCoroutine ()
 Return an IEnumerator to use with a yield in a Coroutine More...
 
Fiber WaitFor (Fiber anotherFiber)
 Wait for another fiber to complete, starting it if needed More...
 
Fiber Timeout (float seconds)
 Exit later fiber operations if the time supplied is exceeded More...
 
Fiber WaitFor (Func< Fiber, Fiber > getFiber)
 Wait for another fiber to complete, starting it if needed - value set by return value of a function More...
 
Fiber GlobalOnError (Action< string > actor)
 Set a global (app-wide) error catch lambda. All fibers without a local override will come here. The default is to write to the Unity console. More...
 
Fiber OnError (Action< string > actor)
 The catch lambda will be called for any exceptions from this fiber or any fibers called with WaitFor More...
 
Fiber Error (string message)
  //#TBD#// More...
 
Fiber Error (Func< Fiber, string > messageLambda)
  //#TBD#// More...
 
override string ToString ()
 Return Fiber contents and current state More...
 
Fiber Log (string message, bool warning=false)
 Write to the Unity console (optionally as a warning entry) More...
 
Fiber WaitFor (Emitter emitter, string name=null)
 Wait for an emitter to fire More...
 
Fiber WaitFor (Func< Fiber, Emitter > getEmitter, string name=null)
 Wait for an emitter passed by function return to fire More...
 
Fiber Fire (Emitter emitter)
 Fire an emitter at this point in the Fiber sequence More...
 
Fiber Fire (Func< Fiber, Emitter > getEmitter)
 Fire an emitter at this point in the Fiber sequence More...
 
Fiber CancelOn (Emitter emitter)
 Cancel/Abort/Exit current fiber if an emitter fires More...
 
Fiber SkipFrames (int framesToSkip)
 Wait a specific count of Update, FixedUpdate or LateUpdate frames More...
 
Fiber SkipFrames (Func< Fiber, int > getter)
 Wait a specific count of Update, FixedUpdate or LateUpdate frames - value passed by function return to More...
 
Fiber WaitFor (IEnumerator enumerator)
 Wait for a C# IEnumerator/Unity Coroutine to take a step More...
 
Fiber WaitFor (Func< Fiber, IEnumerator > getter)
 Wait for a C# IEnumerator/Unity Coroutine to take a step - value passed by function return More...
 
Fiber WaitFor (int framesBetweenChecks, IEnumerator enumerator)
  //#TBD#// More...
 
Fiber WaitFor (float seconds)
 Wait the specified time in game-seconds More...
 
Fiber WaitFor (Func< Fiber, float > getSeconds)
 Wait the specified time in game-seconds - value passed by function return More...
 
Fiber WaitRealtime (float seconds)
 Wait the specified time in real-world seconds More...
 
Fiber WaitRealtime (Func< Fiber, float > getSeconds)
 Wait the specified time in real-world seconds - value passed by function return More...
 
Fiber WaitFor (Task task)
 Convert Task activities to Coroutines to behave well with the rest of Unity More...
 
Fiber WaitFor (Func< Fiber, Task > getTask)
 Convert Task activities to Coroutines to behave well with the rest of Unity - value passed by function return More...
 

Public Attributes

Emitter OnComplete
 
bool Running
 
Fiber OnUpdates => AddAction(_ => node.MoveTo(Queue.Update), "OnUpdates")
 Return Fiber processing to frame Update queue More...
 
Fiber OnFixedUpdates => AddAction(_ => node.MoveTo(Queue.FixedUpdate), "OnFixedUpdates")
 Move Fiber processing to FixedUpdate queue More...
 
Fiber OnLateUpdates => AddAction(_ => node.MoveTo(Queue.LateUpdate), "OnLateUpdates")
 Move Fiber processing to LateUpdate queue More...
 
Fiber End => AddAction(NextAction).AddAction(_ => blockStack.Pop(), "End")
 Begin/End block - use Break() to create an if More...
 
Fiber Again => AddAction(_ => action = blockStack.Top).AddAction(NextAction).End
 Begin/Again repeating operations. Use Break() or Exit() to leave More...
 
Fiber Else => AddAction(_ => Break(2), "Else").AddAction(NextAction)
 Standard If // Else // Then branch More...
 
Fiber Then => AddAction(NextAction, "Then")
 Standard If // Else // Then branch More...
 
bool Debugging = false
 Displays Do() and action events on Unity console More...
 
readonly Fifo< WorkerWorkers = Fifo<Worker>.Instance
 List of workers associated with Fiber actions More...
 

Properties

static Fiber Instance [get]
 Precompile an instance of a fiber command More...
 
static Fiber Start [get]
 Prepare a Fiber and place it on the Update queue More...
 
Fiber Begin [get]
 Loops and Blocks - Begin/End, Begin/Again, Begin-Repeat More...
 
Fiber ExitOnError [get]
 Exceptions in this fiber will cause the fiber to exit More...
 

Detailed Description

Member Function Documentation

◆ Action()

delegate void Askowl.Fiber.Action ( Fiber  fiber)

◆ AsCoroutine()

IEnumerator Askowl.Fiber.AsCoroutine ( )

◆ Break()

void Askowl.Fiber.Break ( )

Break a Begin/End/Repeat/Again block

Definition at line 217 of file Fiber.cs.

◆ BreakIf()

Fiber Askowl.Fiber.BreakIf ( Func< Fiber, bool >  isBreak)

◆ CancelOn()

Fiber Askowl.Fiber.CancelOn ( Emitter  emitter)

◆ Context< T >() [1/4]

T Askowl.Fiber.Context< T > ( )

Retrieve the context as a class type - null for none or wrong type

Type Constraints
T :class 
T :context 
T :typeof 
T :T 
T :Value 
T :as 
T :T 

◆ Context< T >() [2/4]

Fiber Askowl.Fiber.Context< T > ( value)

Set the context to an instance of a type

Type Constraints
T :class 

Definition at line 126 of file Fiber.cs.

◆ Context< T >() [3/4]

T Askowl.Fiber.Context< T > ( string  name)

Retrieve the context as a class type - null for none or wrong type

Type Constraints
T :class 
T :context 
T :name 
T :Value 
T :as 
T :T 

◆ Context< T >() [4/4]

Fiber Askowl.Fiber.Context< T > ( string  name,
value 
)

Set the context to an instance of a type

Type Constraints
T :class 

Definition at line 135 of file Fiber.cs.

◆ Dispose()

void Askowl.Fiber.Dispose ( )

◆ Do()

Fiber Askowl.Fiber.Do ( Action  nextAction,
string  name = null 
)

◆ Error() [1/2]

Fiber Askowl.Fiber.Error ( string  message)

//#TBD#//

Definition at line 301 of file Fiber.cs.

◆ Error() [2/2]

Fiber Askowl.Fiber.Error ( Func< Fiber, string >  messageLambda)

//#TBD#//

Definition at line 306 of file Fiber.cs.

◆ Exit() [1/2]

Fiber Askowl.Fiber.Exit ( )

◆ Exit() [2/2]

Fiber Askowl.Fiber.Exit ( Fiber  fiber)

◆ Finish()

void Askowl.Fiber.Finish ( )

◆ Fire() [1/2]

Fiber Askowl.Fiber.Fire ( Emitter  emitter)

◆ Fire() [2/2]

Fiber Askowl.Fiber.Fire ( Func< Fiber, Emitter getEmitter)

◆ GlobalOnError()

◆ Go() [1/2]

◆ Go() [2/2]

Fiber Askowl.Fiber.Go ( Action  updater)

◆ If()

Fiber Askowl.Fiber.If ( Func< Fiber, bool >  isTrue)

◆ Log()

Fiber Askowl.Fiber.Log ( string  message,
bool  warning = false 
)

◆ OnError()

◆ Repeat()

Fiber Askowl.Fiber.Repeat ( int  count)

◆ SkipFrames() [1/2]

Fiber Askowl.Fiber.SkipFrames ( int  framesToSkip)

◆ SkipFrames() [2/2]

◆ Timeout()

Fiber Askowl.Fiber.Timeout ( float  seconds)

◆ ToString()

override string Askowl.Fiber.ToString ( )

◆ Until()

Fiber Askowl.Fiber.Until ( Func< Fiber, bool >  isTrue)

◆ WaitFor() [1/12]

Fiber Askowl.Fiber.WaitFor ( Emitter  emitter,
string  name = null 
)

◆ WaitFor() [2/12]

Fiber Askowl.Fiber.WaitFor ( float  seconds)

◆ WaitFor() [3/12]

◆ WaitFor() [4/12]

Fiber Askowl.Fiber.WaitFor ( IEnumerator  enumerator)

◆ WaitFor() [5/12]

Fiber Askowl.Fiber.WaitFor ( Func< Fiber, Emitter getEmitter,
string  name = null 
)

◆ WaitFor() [6/12]

Fiber Askowl.Fiber.WaitFor ( Func< Fiber, float >  getSeconds)

◆ WaitFor() [7/12]

◆ WaitFor() [8/12]

Fiber Askowl.Fiber.WaitFor ( int  framesBetweenChecks,
IEnumerator  enumerator 
)

//#TBD#//

◆ WaitFor() [9/12]

◆ WaitFor() [10/12]

◆ WaitFor() [11/12]

Fiber Askowl.Fiber.WaitFor ( Fiber  anotherFiber)

◆ WaitFor() [12/12]

◆ WaitRealtime() [1/2]

Fiber Askowl.Fiber.WaitRealtime ( float  seconds)

◆ WaitRealtime() [2/2]

Fiber Askowl.Fiber.WaitRealtime ( Func< Fiber, float >  getSeconds)

Member Data Documentation

◆ Again

Fiber Askowl.Fiber.Again => AddAction(_ => action = blockStack.Top).AddAction(NextAction).End

◆ Debugging

bool Askowl.Fiber.Debugging = false

◆ Else

Fiber Askowl.Fiber.Else => AddAction(_ => Break(2), "Else").AddAction(NextAction)

Standard If // Else // Then branch

Definition at line 242 of file Fiber.cs.

◆ End

Fiber Askowl.Fiber.End => AddAction(NextAction).AddAction(_ => blockStack.Pop(), "End")

◆ OnFixedUpdates

Fiber Askowl.Fiber.OnFixedUpdates => AddAction(_ => node.MoveTo(Queue.FixedUpdate), "OnFixedUpdates")

◆ OnLateUpdates

Fiber Askowl.Fiber.OnLateUpdates => AddAction(_ => node.MoveTo(Queue.LateUpdate), "OnLateUpdates")

◆ OnUpdates

Fiber Askowl.Fiber.OnUpdates => AddAction(_ => node.MoveTo(Queue.Update), "OnUpdates")

◆ Then

Fiber Askowl.Fiber.Then => AddAction(NextAction, "Then")

Standard If // Else // Then branch

Definition at line 245 of file Fiber.cs.

◆ Workers

readonly Fifo<Worker> Askowl.Fiber.Workers = Fifo<Worker>.Instance

Property Documentation

◆ Begin

Fiber Askowl.Fiber.Begin
get

◆ ExitOnError

Fiber Askowl.Fiber.ExitOnError
get

◆ Instance

Fiber Askowl.Fiber.Instance
staticget

◆ Start

Fiber Askowl.Fiber.Start
staticget

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