new-thunk - npm
new-thunk
is Thunk implementation.
it supports browser Chrome, Firefox, ie11, ie9, ie8. (tested)
also supports node.js.
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>
you can use Thunk.
var Thunk = require('new-thunk');
// you can use Thunk
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);
});
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);
});
MIT