1. Type definition 2. Chain definition 3. Enqueue definition
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•8h ago
ath92•7h ago
At least this stackoverflow answer suggests the handlers are GC’ed: https://stackoverflow.com/questions/79448475/are-promise-han...
jameshart•7h 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•7h 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•6h ago
ameliaquining•5h ago
bigiain•2h ago
Modern frontend development performance best practise is to allow for garbage collection only when the browser crashes.