function-bootstrapper
v1.3.0
Published
A bootstrapper library
Downloads
3
Readme
Bootstrapper
Example ES6:
import Bootstrapper from 'function-bootstrapper';
import Promise from 'bluebird';
const bootstrap = new Bootstrapper({
ignoreError: true,
chain: [
{
promise: true,
payload: {
"importantData": "Hello"
},
function: function(payload) {
return new Promise((resolve, reject) => {
doSomething(payload, (error) => {
if (error){
reject(error);
} else {
resolve();
}
});
});
}
},
{
payload: '{"json":true}',
function: function(payload){
return JSON.parse(payload);
}
}
]
});
bootstrap.on('progress',console.log);
bootstrap.promise.then(() => {
console.log("Finished bootstrap");
}).catch(console.error);
Example normal:
const Bootstrapper = require('function-bootstrapper');
const Promise = require('bluebird');
const bootstrap = new Bootstrapper({
ignoreError: true,
chain: [
{
promise: true,
payload: {
"importantData": "Hello"
},
function: function(payload) {
return new Promise(function (resolve, reject) {
doSomething(payload, (error) => {
if (error){
reject(error);
} else {
resolve();
}
});
});
}
},
{
payload: '{"json":true}',
function: function(payload){
return JSON.parse(payload);
}
}
]
});
bootstrap.on('progress',console.log);
bootstrap.promise.then(function () {
console.log("Finished bootstrap");
}).catch(console.error);
Typedefs
BootChainFragment : Object
Kind: global typedef
Properties
| Name | Type | Description | | --- | --- | --- | | promise | Boolean | If false, it needs to be sync | | function | function | | | payload | * | The payload is the first arguement for the function | | ignoreError | Boolean | Don't reject if a error occurs, but only for this fragment | | pipeTo | function | This function will be executed after the main function finished. The first argument is the result of the function. |
BootstrapperConfig : Object
Kind: global typedef
Properties
| Name | Type | Description | | --- | --- | --- | | ignoreError | Boolean | Don't reject if a error occurs | | parallel | Boolean | Run Bootchain parallel, how much operation parallel is defined with limit. You only need to define one property, parallel or limit. If not limit is set and parallel is true, cpu core count will be used. | | limit | int | How much operation parallel. You only need to define one property, parallel or limit. If not limit is set and parallel is true, cpu core count will be used. | | chain | BootChainFragment | [] |