In JavaScript one can cause code to be executed immediately after the current bit of code has finished executing a la setImmediate or setTimeout(..., 0).
What is the correct term for referring to the gap in execution?
I want to know because I am writing a utility for unit testing that allows a test to continue once one of these gaps has occurred and I want to give it a meaningful name.
At present my code looks like this and the function is just called wait:
export default function wait(done, ...callbacks) {
let callbackIndex = 0;
function invokeNext() {
if (typeof callbacks[callbackIndex] === 'function') {
setImmediate(() => {
try {
callbacks[callbackIndex]();
}
catch (e) {
return done(e);
}
callbackIndex += 1;
invokeNext();
});
} else {
return done();
}
}
invokeNext();
}
It is used like this:
wait(done, () => {
//... assert something after first code gap
},
() => {
//... assert something after second code gap
});