How to use the hoek.once function in hoek

To help you get started, we’ve selected a few hoek 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 DefinitelyTyped / DefinitelyTyped / hoek / hoek-tests.ts View on Github external
nextFn();
console.log('Do this first');

// Results in:
//
// Do this first
// Do this later

// once(fn)

myFn = () => {
    console.log('Ran myFn');
};

let onceFn = Hoek.once(myFn);
onceFn(); // results in "Ran myFn"
onceFn(); // results in undefined

// ignore

Hoek.ignore();

// uniqueFilename(path, extension)

let result1 = Hoek.uniqueFilename('./test/modules', 'txt'); // results in "full/path/test/modules/{random}.txt"

// isInteger(value)

result = Hoek.isInteger('23');
github davidhealey / waistline / node_modules / npm / node_modules / request / node_modules / hawk / node_modules / sntp / lib / index.js View on Github external
// Ensure callback is only called once

    var finish = function (err, result) {

        if (timeoutId) {
            clearTimeout(timeoutId);
            timeoutId = 0;
        }

        socket.removeAllListeners();
        socket.once('error', internals.ignore);
        socket.close();
        return callback(err, result);
    };

    finish = Hoek.once(finish);

    // Create UDP socket

    var socket = Dgram.createSocket('udp4');

    socket.once('error', function (err) {

        return finish(err);
    });

    // Listen to incoming messages

    socket.on('message', function (buffer, rinfo) {

        var received = Date.now();
github hapijs / hapi / lib / payload.js View on Github external
internals.parse = function (request, next) {

    var output = request.route.payload.output;      // Output: 'data', 'stream', 'file'
    var source = request.raw.req;

    // Content-encoding

    var contentEncoding = source.headers['content-encoding'];
    if (contentEncoding === 'gzip' || contentEncoding === 'deflate') {
        var decoder = (contentEncoding === 'gzip' ? Zlib.createGunzip() : Zlib.createInflate());
        next = Hoek.once(next);                                                                     // Modify next() for async events
        decoder.once('error', function (err) {

            return next(Boom.badRequest('Invalid compressed payload', err));
        });

        source = source.pipe(decoder);
    }

    // Tap request

    var tap = request._tap();
    if (tap) {
        source = source.pipe(tap);
    }

    // Multipart
github guerrerocarlos / bitcoin-receive-payments / node_modules / sntp / lib / index.js View on Github external
options = {};
    }

    const settings = Hoek.clone(options);
    settings.host = settings.host || 'time.google.com';
    settings.port = settings.port || 123;
    settings.resolveReference = settings.resolveReference || false;

    // Declare variables used by callback

    let timeoutId = null;
    let sent = 0;

    // Ensure callback is only called once

    const finish = Hoek.once((err, result) => {

        clearTimeout(timeoutId);

        socket.removeAllListeners();
        socket.once('error', Hoek.ignore);

        try {
            socket.close();
        }
        catch (ignoreErr) { }       // Ignore errors if the socket is already closed

        return callback(err, result);
    });

    // Set timeout
github graalvm / graaljs / deps / npm / node_modules / request / node_modules / hawk / node_modules / sntp / lib / index.js View on Github external
options = {};
    }

    const settings = Hoek.clone(options);
    settings.host = settings.host || 'pool.ntp.org';
    settings.port = settings.port || 123;
    settings.resolveReference = settings.resolveReference || false;

    // Declare variables used by callback

    let timeoutId = 0;
    let sent = 0;

    // Ensure callback is only called once

    const finish = Hoek.once((err, result) => {

        if (timeoutId) {
            clearTimeout(timeoutId);
            timeoutId = 0;
        }

        socket.removeAllListeners();
        socket.once('error', Hoek.ignore);
        socket.close();
        return callback(err, result);
    });

    // Create UDP socket

    const socket = Dgram.createSocket('udp4');
github epsil / spotgen / node_modules / sntp / lib / index.js View on Github external
// Ensure callback is only called once

    var finish = function (err, result) {

        if (timeoutId) {
            clearTimeout(timeoutId);
            timeoutId = 0;
        }

        socket.removeAllListeners();
        socket.once('error', internals.ignore);
        socket.close();
        return callback(err, result);
    };

    finish = Hoek.once(finish);

    // Create UDP socket

    var socket = Dgram.createSocket('udp4');

    socket.once('error', function (err) {

        return finish(err);
    });

    // Listen to incoming messages

    socket.on('message', function (buffer, rinfo) {

        var received = Date.now();
github sx1989827 / DOClever / Desktop / node_modules / sntp / lib / index.js View on Github external
options = {};
    }

    const settings = Hoek.clone(options);
    settings.host = settings.host || 'time.google.com';
    settings.port = settings.port || 123;
    settings.resolveReference = settings.resolveReference || false;

    // Declare variables used by callback

    let timeoutId = null;
    let sent = 0;

    // Ensure callback is only called once

    const finish = Hoek.once((err, result) => {

        clearTimeout(timeoutId);

        socket.removeAllListeners();
        socket.once('error', Hoek.ignore);

        try {
            socket.close();
        }
        catch (ignoreErr) { }       // Ignore errors if the socket is already closed

        return callback(err, result);
    });

    // Set timeout
github concur / skipper / node_modules / sntp / lib / index.js View on Github external
options = {};
    }

    const settings = Hoek.clone(options);
    settings.host = settings.host || 'time.google.com';
    settings.port = settings.port || 123;
    settings.resolveReference = settings.resolveReference || false;

    // Declare variables used by callback

    let timeoutId = null;
    let sent = 0;

    // Ensure callback is only called once

    const finish = Hoek.once((err, result) => {

        clearTimeout(timeoutId);

        socket.removeAllListeners();
        socket.once('error', Hoek.ignore);

        try {
            socket.close();
        }
        catch (ignoreErr) { }       // Ignore errors if the socket is already closed

        return callback(err, result);
    });

    // Set timeout
github hapijs / hapi / lib / protect.js View on Github external
internals.Protect.prototype.run = function (next, enter) {              // enter: function (exit)

    const finish = Hoek.once((arg0, arg1, arg2) => {

        this._error = null;
        return next(arg0, arg1, arg2);
    });

    if (this.domain) {
        this._error = (err) => {

            return finish(Boom.badImplementation('Uncaught error', err));
        };
    }

    return enter(finish);
};