@dizmo/buffered
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.20 • Public • Published

    Build Status Coverage Status

    @dizmo/functions-buffered

    A Node.js module that returns a buffered and cancelable version for the provided function. The buffered function does not execute before the specified delay passes upon which it executes exactly once, no matter have many times it gets invoked in between. Also upon the invocation of the buffering function a promise is returned. Further, the cancellation of a particular invocation is only possible while the specified delay has not passed.

    Usage

    Install

    npm install @dizmo/functions-buffered --save

    Require

    var lib = require('@dizmo/functions-buffered');

    Examples

    var buffered = require('@dizmo/functions-buffered').buffered;
    var fn = buffered((t) => {
        return new Date() - t;
    }, 200);
    
    fn(new Date()).then((res) => {
        console.debug(res);
    }).catch((err) => {
        console.error(err);
    });
    var buffered = require('@dizmo/functions-buffered').buffered;
    var fn = buffered(() => {
        throw new Error("won't be thrown");
    }, 600);
    
    fn().then((res) => { // won't execute (due to `fn.cancel`)
        console.debug(res);
    }).catch((err) => {
        console.error(err);
    });
    
    fn.cancel();

    Development

    Build

    npm run build

    Lint

    npm run lint

    with fixes:

    npm run lint:fix

    Test

    npm run test

    Cover

    npm run cover

    Copyright

    © 2018 dizmo AG, Switzerland

    Install

    npm i @dizmo/buffered

    DownloadsWeekly Downloads

    0

    Version

    1.1.20

    License

    ISC

    Unpacked Size

    7.98 kB

    Total Files

    7

    Last publish

    Collaborators