Variable detachedConst

detached: Job<unknown> = ...

A special Job with no parents, that can be used to create standalone jobs. detached.start() returns a new detached job, detached.run() can be used to run code that expects to create a child job, and detached.bind() can wrap a function to work without a parent job.

(Note that such detached child jobs must exit themselves or be stopped explicitly from outside, or else they may "run" forever, never running their cleanup callbacks. Unlike other jobs, they don't end when their parent does because the detached job never "ends".)

The detached job has a few special features and limitations:

  • It can't be ended, thrown, return()ed, etc. -- you'll get an error

  • It can't have any cleanup functions added: no do, must, onError, etc., and thus also can't have any native promise, abort signal, etc. used. You can call its release() method, but nothing will actually be registered and the returned callback is a no-op.

  • Unhandled errors from jobs without parents (and errors from any job's cleanup functions) are sent to the detached job for handling. This means whatever you set as the detached job's .asyncCatch() handler will receive them. (Its default is Promise.reject, causing an unhandled promise rejection.)