Fork class

Creates an Effect description that instructs the middleware to perform a non-blocking call on fn

  • fn is a Generator function, or normal function which returns a Future as result.

  • args and namedArgs are values to be passed as arguments to fn

  • Catch will be invoked for uncaught errors.

  • Finally will be invoked in any case after call.

  • detached determines if the Task is attached or not. If false then task is attached and when the parent terminates it also terminates. If true then it is Spawn effect which is independent from its parent. By default it is false.

  • name is an optional name for the Task meta.

Fork effects returns a Task object.

Notes

Fork, like Call, can be used to invoke both normal and Generator functions. But, the calls are non-blocking, the middleware doesn't suspend the Generator while waiting for the result of fn. Instead as soon as fn is invoked, the Generator resumes immediately.

Fork, alongside Race, is a central Effect for managing concurrency between Sagas.

The result of yield Fork(fn, args:[...]) is a Task object. An object with some useful methods and properties.

All forked tasks are attached to their parents. When the parent terminates the execution of its own body of instructions, it will wait for all forked tasks to terminate before returning.

Error propagation

Errors from child tasks automatically bubble up to their parents. If any forked task raises an uncaught error, then the parent task will abort with the child Error, and the whole Parent's execution tree (i.e. forked tasks + the main task represented by the parent's body if it's still running) will be cancelled.

Cancellation of a forked Task will automatically cancel all forked tasks that are still executing. It'll also cancel the current Effect where the cancelled task was blocked (if any).

If a forked task fails synchronously (ie: fails immediately after its execution before performing any async operation), then no Task is returned, instead the parent will be aborted as soon as possible (since both parent and child execute in parallel, the parent will abort as soon as it takes notice of the child failure).

To create detached forks, use Spawn instead or set detached to true.

Inheritance
Implementers

Constructors

Fork(Function fn, {List? args, Map<Symbol, dynamic>? namedArgs, Function? Catch, Function? Finally, String? name, bool detached = false, Result? result})
Creates an instance of a Fork effect.

Properties

args List?
Arguments of the function to call
final
Catch Function?
A Generator function or a normal function to invoke for uncaught errors.
final
detached bool
Determines if returning Task is attached or not.
final
Finally Function?
A Generator function or a normal function to invoke in any case after call.
final
fn Function
A Generator function or a normal function to call.
final
hashCode int
The hash code for this object.
no setterinherited
name String?
Meta name of function
final
namedArgs Map<Symbol, dynamic>?
Named arguments of the function to call
final
result Result?
Result after effect is resolved.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getDefinition() Map<String, dynamic>
Returns all properties of effect as a dictionary object
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited