Skip to content

Instantly share code, notes, and snippets.

View dpjayasekara's full-sized avatar

dpjayasekara

View GitHub Profile
exports.setup = setupNextTick;
function setupNextTick() {
// ...redacted...
// tickInfo is used so that the C++ code in src/node.cc can
// have easy access to our nextTick state, and avoid unnecessary
// calls into JS land.
// runMicrotasks is used to run V8's micro task queue.
function startup() {
// ...redacted...
setupProcessObject();
// ...redacted...
setupV8();
// ...redacted...
NativeModule.require('internal/process/warning').setup();
NativeModule.require('internal/process/next_tick').setup();
// ...redacted...
}
function _tickCallback() {
let tock;
do {
while (tock = queue.shift()) {
const asyncId = tock[async_id_symbol];
emitBefore(asyncId, tock[trigger_async_id_symbol]);
if (destroyHooksExist())
emitDestroy(asyncId);
const callback = tock.callback;
exports.setup = setupNextTick;
function setupNextTick() {
// ...redacted...
const [
tickInfo,
runMicrotasks
] = process._setupNextTick(_tickCallback);
void Environment::Start(int argc,
const char* const* argv,
int exec_argc,
const char* const* exec_argv,
bool start_profiler_idle_notifier) {
// ...redacted...
SetupProcessObject(this, argc, argv, exec_argc, exec_argv);
// ...redacted...
}
Module.runMain = function() {
// Load the main module--the command line argument.
Module._load(process.argv[1], null, true);
// Handle any nextTicks added in the first tick of the program
process._tickCallback();
};
function mergeXpathList(xpathList) {
return xpathList.reduce((output, curr) => {
const out = output;
if (out.length === 0) { return [curr]; }
for (let i = 0; i < out.length; i += 1) {
if (curr.includes(out[i])) {
out[i] = curr;
return out;
}
function processImmediate() {
const queue = outstandingQueue.head !== null ?
outstandingQueue : immediateQueue;
var immediate = queue.head;
const tail = queue.tail;
// Clear the linked list early in case new `setImmediate()` calls occur while
// immediate callbacks are executed
queue.head = queue.tail = null;
@dpjayasekara
dpjayasekara / promisify.js
Created October 14, 2019 21:09 — forked from deepal/promisify.js
Promisify a Callback-accepting function
function SquareAsync (number, callback) {
if (number > 100) {
process.nextTick(() => {
callback(new Error('number is too large for me to handle'));
});
return;
}
setTimeout(() => {
callback(null, number ** 2);
@dpjayasekara
dpjayasekara / nodebunyan
Created October 14, 2019 21:09 — forked from deepal/nodebunyan
Run node with the output piped to bunyan
#!/bin/bash
NODE_VERSION=`node --version`
BUNYAN_VERSION=`bunyan --version | awk '{print $2}'`
echo "Running with node version: "$NODE_VERSION" and bunyan version: "$BUNYAN_VERSION"..."
node $* | bunyan