Skip to content

LightSpeedWorks/new-thunk

Repository files navigation

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

Releases

No releases published

Packages

No packages published