single-init
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

SingleInit

Installation

npm install single-init --save

Example usage:

var SingleInit = require('sinlge-init').default;
//or, for modern sutff:
import SingleInit from 'single-init';

var products = new SingleInit(function initFunction(done) {
    db.getProducts(done);
});

products.get(function (err, products) {
    //...
});

//or use promise api:

products.get().then(function (products) {
    //...
}, function onError(err) {
    //...
});

//which is very handy with async/await:

try {
    let products = await products.get();
    let productsGotAgain = await products.get();
    let getThemOnceMore = await products.get();
} catch (err) {
    //on products.get error
}

//You can read state:

products.get();
console.log(products.state); // will print out 'initaliznig';
//state may be one of: 'cold', 'initaliznig', 'complete'

In the above examples initFunction will be called only once

License - ISC (very permisive, shorter version of MIT)

ISC License

Copyright (c) [2016], [Szymon Wygnański]

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i single-init

    Weekly Downloads

    14

    Version

    1.1.2

    License

    ISC

    Last publish

    Collaborators

    • szymon.wygnanski