Search code examples
javascriptterminology

What is the technical name for, "Unrelated asynchronous call stacks?" I want to say, "How do I wait until an unrelated ___ completes?"


Imagine code like this (this example errors, but it's only meant to clarify my question):

// In one code block...
const async1 = new Promise((resolve) => {
  addListenerThatResolvesWhenAsync2Completes(resolve);
});


// Potentially, in another code block. 
// Potentially, in a separate event loop iteration.
setTimeout(() => dispatchAsync2CompleteEvent(), delay); // this setTimeout "spawns" async2
  1. async1 is a Promise, async2 is a setTimeout
  2. Both are asynchronous.
  3. They exist in separate chains; async1 waits for async2 to complete, but otherwise, they are unrelated.

If these were both promises, I wouldn't need to ask this question. I think people would understand what I meant if I said, "Promises running in parallel." But as far as I understand it, setTimeout - and therefore async2 - doesn't create a Promise. Is there a term that means "Promises and setTimeout's running in parallel with unrelated call stacks?"

If this were another programming language, I might be able to say "separate threads" or "separate processes", but neither of those are technically correct in the given example.


Solution

  • The terms "threads" and "processes" refer to the specific operating system resources (or runtime, for threads managed by a virtual machine).

    If you want to be less specific, just say "asynchronous tasks" or "asynchronous operations", which can run concurrently with each other. This means any sequence of code executions that are spawned in a (usually linear) chain, forming a unit of execution with a result.

    Notice that promises do not "run", just like they are not "executed" - a promise represent an asynchronous result not a callable function.