@flox/fork

0.1.5 • Public • Published

fork

Build status Git tag NPM version Code style

Non blocking async call effects.

Installation

$ npm install @floxjs/fork

Usage

import forkEffect, {fork, join} from '@floxjs/fork'

const store = applyMiddleware(flo(), forkEffect)(createStore)(reducer, {})

function * child () {
  yield delay(5)
  return 'foo'
}

store.dispatch(function * () {
  const task = yield fork(child)

  // do some things

  yield join(task) // => 'foo'

})

API

fork(fn)

Action creator.

  • fn - function, generator, or iterator to fork

Returns: a task

join(task)

Action creator.

  • task - task to block on

Returns: result of task

cancel(task)

Action creator. Throws error in running task with message: 'TaskCanceled'.

  • task - task to cancel

taskRunner(dispatch)

Runs tasks. Used internally by koax.

  • dispatch - dispatch function

Returns: dispatch

task.isRunning()

Returns: whether task is running

task.result()

Returns: the result of the task

task.error()

Returns: the error thrown by the task

###task.cancel() Cancels task

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @flox/fork

Weekly Downloads

5

Version

0.1.5

License

MIT

Last publish

Collaborators

  • flox