1. Type definition 2. Chain definition 3. Enqueue definition
Transpilation does not change the fact that the input is these 3 lines of code in 2 different languages.
I wonder why are you downvoted for being as factual and neutral as it is technically possible.
It creates 1 object allocation per enqueue.
async function runTasks(tasks: Job[]) { for (let task of tasks) { try { await task() } catch (e) { } } }
`prom.then(fn)` creates a new promise. The new promise’s resolver function is the `fn` inside `then(fn)`, and the new promise’s asynchronous computation is the original promise’s resolver function.
chain
.then(job)
.catch((err) => {
console.error(err);
return job();
});
Otherwise failures would need to be logged by the job itself before rejecting the promise. type Job = () => Promise<unknown>;
This is not JS.
lerp-io•6mo ago
ath92•6mo ago
At least this stackoverflow answer suggests the handlers are GC’ed: https://stackoverflow.com/questions/79448475/are-promise-han...
jameshart•6mo ago
The original promise needs to reference the chained promise, not the other way round.
As jobs complete I would expect the top of the chain to be eligible to be garbage collected.
paulddraper•6mo ago
(If the runtime maintains async stack traces, that could be an issue...but that is a common issue, and the stack depth is limited.)
bapak•6mo ago
ameliaquining•6mo ago
bigiain•6mo ago
Modern frontend development performance best practise is to allow for garbage collection only when the browser crashes.
moralestapia•6mo ago
Inviz•6mo ago
Even if you are doing `then().then()`, something _else_ in the code base could retain the promise somehow and then your whole chain isn't GCable!
For example https://github.com/rxaviers/async-pool library that implements concurrency for async iterators (and uses promise.race) subtly creates GC pressure which you dont see until you make a whole lot of calls and suddenly its slow