versatica / awaitqueue

JavaScript utility to enqueue async tasks for Node.js and the browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow to pass arguments to task

piranna opened this issue · comments

At

async push<T>(task: AwaitQueueTask<T>, name?: string): Promise<T>
, allow to have arguments after name that will be passed as arguments to the call of the task when executed. This would allow to pass it parameters without needing to use nested functions and get them from closures.

This would require a complete different API and internal implementation. Passing a nested function is not a big deal (not even at perf level) so this is just a cosmetic thing IMHO.

My main concern is about being name optional, that makes things more difficult to understand and do, otherwise implementation is trivial, just a matter of calling task.apply(). Regarding performance, I don't have numbers, but definitely it introduce a penaly since the task function objects needs to be created each time instead of just only once, consuming CPU and memory until garbage-collected (that was the reason why other functions like setTimeout() allow to pass parameters after the timeout value).