new-thunk

0.0.2 • Public • Published

new-thunk - npm

new-thunk is Thunk implementation.
it supports browser Chrome, Firefox, ie11, ie9, ie8. (tested)
also supports node.js.

INSTALL:

NPM NPM

for node.js

$ npm install new-thunk --save

or

for browsers

https://lightspeedworks.github.io/new-thunk/new-thunk.js

<script src="https://lightspeedworks.github.io/new-thunk/new-thunk.js"></script>

PREPARE:

you can use Thunk.

var Thunk = require('new-thunk');
// you can use Thunk

USAGE:

Thunk Specification

Thunk(setup)

how to make thunk.

thunk = Thunk(
  function setup(callback) {
    // async process -> callback(error, value)
    try { callback(null, 'value'); }
    catch (error) { callback(error); }
  }
);
// setup(
//  function callback(error, value) {},

example

var thunk = Thunk(
  function setup(callback) {
    setTimeout(function () {
      if (Math.random() < 0.5) callback(null, 'value');
      else callback(new Error('error'));
    }, 100);
  }
);

thunk(function callback(error, value) {
  if (error) console.error(error);
  else console.info(value);
});

thunk(callback)

how to use thunk.

thunk = thunk(
  function callback(error, value) {});

example

thunk = thunk(function callback(error, value) {
  if (error) console.error(error);
  else console.info(value);
});

TO DO LIST

To Do List

LICENSE:

MIT

Readme

Keywords

Package Sidebar

Install

npm i new-thunk

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • lightspeedc