How to use the once.strict function in once

To help you get started, we’ve selected a few once examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DonutEspresso / big-json / lib / index.js View on Github external
function _stringify(opts, callback) {
    assert.object(opts, 'opts');
    assert.func(callback, 'callback');

    let stringified = '';
    const stringifyStream = createStringifyStream(opts);
    const passthroughStream = new stream.PassThrough();
    const cb = once(callback);

    // setup the passthrough stream as a sink
    passthroughStream.on('data', function(chunk) {
        stringified += chunk;
    });

    passthroughStream.on('end', function() {
        return cb(null, stringified);
    });

    // don't know what errors stringify stream may emit, but pass them back
    // up.
    stringifyStream.on('error', function(err) {
        return cb(err);
    });
github DonutEspresso / big-json / lib / index.js View on Github external
function _parse(opts, callback) {
    assert.object(opts, 'opts');
    assert.string(opts.body, 'opts.body');
    assert.func(callback, 'callback');

    const sourceStream = intoStream(opts.body);
    const parseStream = createParseStream();
    const cb = once(callback);

    parseStream.on('data', function(data) {
        return cb(null, data);
    });

    parseStream.on('error', function(err) {
        return cb(err);
    });

    sourceStream.pipe(parseStream);
}

once

Run a function exactly one time

ISC
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis

Popular once functions