@laserware/stasis
    Preparing search index...

    Function fork

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

      returns a Task object.

      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.

      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.

      Type Parameters

      • Fn extends (...args: any[]) => any

      Parameters

      • fn: Fn

        A Generator function, or normal function which returns a Promise as result

      • ...args: Parameters<Fn>

        An array of values to be passed as arguments to fn

      Returns ForkEffect<SagaReturnType<Fn>>

    • 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')

      Type Parameters

      • Ctx extends { [P in string]: (this: Ctx, ...args: any[]) => any }
      • Name extends string

      Parameters

      Returns ForkEffect<SagaReturnType<Ctx[Name]>>

    • 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.

      Type Parameters

      • Ctx extends { [P in string]: (this: Ctx, ...args: any[]) => any }
      • Name extends string

      Parameters

      • ctxAndFnName: { context: Ctx; fn: Name }
      • ...args: Parameters<Ctx[Name]>

      Returns ForkEffect<SagaReturnType<Ctx[Name]>>

    • Same as fork(fn, ...args) but supports passing a this context to fn. This is useful to invoke object methods.

      Type Parameters

      • Ctx
      • Fn extends (this: Ctx, ...args: any[]) => any

      Parameters

      • ctxAndFn: [Ctx, Fn]
      • ...args: Parameters<Fn>

      Returns ForkEffect<SagaReturnType<Fn>>

    • 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.

      Type Parameters

      • Ctx
      • Fn extends (this: Ctx, ...args: any[]) => any

      Parameters

      • ctxAndFn: { context: Ctx; fn: Fn }
      • ...args: Parameters<Fn>

      Returns ForkEffect<SagaReturnType<Fn>>