Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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');
// 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();
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
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
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');
// 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();
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
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
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);
};