1.3.0 • Published 7 years ago

function-bootstrapper v1.3.0

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

Bootstrapper

Travis npm
A bootstrapper library

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

NameTypeDescription
promiseBooleanIf false, it needs to be sync
functionfunction
payload*The payload is the first arguement for the function
ignoreErrorBooleanDon't reject if a error occurs, but only for this fragment
pipeTofunctionThis function will be executed after the main function finished. The first argument is the result of the function.

BootstrapperConfig : Object

Kind: global typedef
Properties

NameTypeDescription
ignoreErrorBooleanDon't reject if a error occurs
parallelBooleanRun 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.
limitintHow 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.
chainBootChainFragment[]
1.3.0

7 years ago

1.2.1

7 years ago

1.1.1

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago