Skip to main content

Melon.std.async.nextTick(delay?)

Creates a new event loop branch with an optional execution delay and returns the ellapsed time.

Status: stable
Returns: number

Parameters

NameTypeDescription
delaynumber?The delay that defines the execution behavior

Example usage

const { nextTick } = Melon.std.async;

async function branchedFunction1() {
await nextTick(3000);
console.log("Hello from asynchronous context 1!");
}

async function branchedFunction2() {
await nextTick(1000);
console.log("Hello from asynchronous context 2!");
}

async function contextCaller() {
branchedFunction2();
branchedFunction1();
}

contextCaller();

Extra behaviors

ConditionConsequenceWorkaround
Calling the method in a sync context with non-null delayThe current thread will be blocked during the delay timeConsider using await or running this in an async context
Calling asynchronous functions that are using nextTick method inside Promise.all or Promise.anyAll the tasks will be blocked and the actions will not happen as exceptedSee issue #256