Start a nested job within the currently-active job. (Shorthand for
calling .start(...) on the active job.)
This function can be called with zero, one, or two arguments:
When called with zero arguments, the new job is returned without any other
initialization.
When called with one argument that's a function (either a SyncStart
or AsyncStart): the function is run inside the new job and receives
it as an argument. It can return a Yielding iterator (such as a
generator or job), a promise, or void. A returned iterator or promise will
be treated as if the method was called with that to begin with; a returned
job will be awaited and its result transferred to the new job
asynchronously. A returned function will be added to the job via must().
When called with one argument that's a Yielding iterator (such as a
generator or an existing job): it's attached to the new job and executed
asynchronously. (Starting in the next available microtask.)
When called with one argument that's a Promise, it's converted to a job
that will end when the promise settles. The resulting job is returned.
When called with two arguments -- a "this" object and a function -- it
works the same as one argument that's a function, except the function is
bound to the supplied "this" before being called.
This last signature is needed because you can't make generator arrows in JS
yet: if you want to start() a generator function bound to the current
this, you'll want to use .start(this, function*() { ...whatever }).
(Note, however, that TypeScript and/or VSCode may require that you give
such a function an explicit this parameter (e.g. .start(this, function *(this) {...}));) in order to correctly infer types inside a generator
function.)
In any of the above cases, if a supplied function throws an error while
starting, the new job will be ended, and the error synchronously re-thrown.
The two-argument variant of start() allows you to pass a "this" object that
will be bound to the initialization function. (It's mostly useful for
generator functions, since generator arrows aren't a thing yet.)
Start a nested job within the currently-active job. (Shorthand for calling .start(...) on the active job.)
This function can be called with zero, one, or two arguments:
When called with zero arguments, the new job is returned without any other initialization.
When called with one argument that's a function (either a SyncStart or AsyncStart): the function is run inside the new job and receives it as an argument. It can return a Yielding iterator (such as a generator or job), a promise, or void. A returned iterator or promise will be treated as if the method was called with that to begin with; a returned job will be awaited and its result transferred to the new job asynchronously. A returned function will be added to the job via
must()
.When called with one argument that's a Yielding iterator (such as a generator or an existing job): it's attached to the new job and executed asynchronously. (Starting in the next available microtask.)
When called with one argument that's a Promise, it's converted to a job that will end when the promise settles. The resulting job is returned.
When called with two arguments -- a "this" object and a function -- it works the same as one argument that's a function, except the function is bound to the supplied "this" before being called.
This last signature is needed because you can't make generator arrows in JS yet: if you want to start() a generator function bound to the current
this
, you'll want to use.start(this, function*() { ...whatever })
.(Note, however, that TypeScript and/or VSCode may require that you give such a function an explicit
this
parameter (e.g..start(this, function *(this) {...}));
) in order to correctly infer types inside a generator function.)In any of the above cases, if a supplied function throws an error while starting, the new job will be ended, and the error synchronously re-thrown.