Skip to content

floxjs/fork

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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