Same as fork([context, fn], ...args)
but supports passing a fn
as string.
Useful for invoking object's methods, i.e.
yield fork([localStorage, 'getItem'], 'redux-saga')
Same as fork([context, fn], ...args)
but supports passing context
and
fn
as properties of an object, i.e.
yield fork({context: localStorage, fn: localStorage.getItem}, 'redux-saga')
.
fn
can be a string or a function.
Same as fork([context, fn], ...args)
but supports passing context
and
fn
as properties of an object, i.e.
yield fork({context: localStorage, fn: localStorage.getItem}, 'redux-saga')
.
fn
can be a string or a function.
Creates an Effect description that instructs the middleware to perform a non-blocking call on
fn
returns a
Task
object.Note
fork
, likecall
, 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 offn
. Instead as soon asfn
is invoked, the Generator resumes immediately.fork
, alongsiderace
, is a central Effect for managing concurrency between Sagas.The result of
yield fork(fn ...args)
is aTask
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.
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.