js-deferrable
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    deferrable

    Build Status

    A npm module with go-like defer implementation

    Installation

    npm install js-deferrable --save
    yarn add js-deferrable
    bower install js-deferrable --save

    Usage

    Javascript

    const deferable = require('js-deferrable');
    const fs = require('fs');
     
    const someFunction = deferrable(async (defer, arg1, arg2) => {
        const desc = await fs.open('someFile.txt');
        defer(()=>fs.close(desc));
        // ...
        // some actions with file, fs.close will be called automaticalle
    });
     
    const someSyncFunction = deferrable((defer, arg1, arg2) => {
            const desc = fs.openSync('someFile.txt');
            defer(()=>fs.closeSync(desc));
            // ...
            // some actions with file, fs.closeSync will be called automaticalle
    }, true)

    TypeScript

    import deferrable from 'js-deferrable';
    import * as fs from require('fs');
     
    const someFunction = deferrable(async (defer, arg1, arg2) => {
        const desc: number = await fs.open('someFile.txt');
        defer(()=>fs.close(desc));
        // ...
        // some actions with file, fs.close will be called automaticalle
    });

    AMD

    define(function(require,exports,module){
      var deferrable = require('js-deferrable');
    });

    Test

    npm run test

    Keywords

    Install

    npm i js-deferrable

    DownloadsWeekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    15.8 kB

    Total Files

    16

    Last publish

    Collaborators

    • zede