Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/internal/process/task_queues.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ function processTicksAndRejections() {

// `nextTick()` will not enqueue any callback when the process is about to
// exit since the callback would not have a chance to be executed.
// The async resource behind each `process.nextTick()` call. A class keeps
// every instance on one map with all fields in-object; an object literal
// with computed symbol keys spills them into a separate property array.
class TickObject {
constructor(callback, args, asyncId, triggerAsyncId) {
this[async_id_symbol] = asyncId;
this[trigger_async_id_symbol] = triggerAsyncId;
this[async_context_frame] = AsyncContextFrame.current();
this.callback = callback;
this.args = args;
}
}

function nextTick(callback) {
validateFunction(callback, 'callback');

Expand All @@ -132,13 +145,7 @@ function nextTick(callback) {
setHasTickScheduled(true);
const asyncId = newAsyncId();
const triggerAsyncId = getDefaultTriggerAsyncId();
const tickObject = {
[async_id_symbol]: asyncId,
[trigger_async_id_symbol]: triggerAsyncId,
[async_context_frame]: AsyncContextFrame.current(),
callback,
args,
};
const tickObject = new TickObject(callback, args, asyncId, triggerAsyncId);
if (initHooksExist())
emitInit(asyncId, 'TickObject', triggerAsyncId, tickObject);
queue.push(tickObject);
Expand Down
Loading