New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(async): async functions in parallel
are now called with additional item index and queue index arguments
#289
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
…itional index parameter test(async): added test for the new index parameter in `parallel`
f431d72
to
b2b9816
Compare
Hey @UnKnoWn-Consortium thanks for the PR 🙏 and sorry for the delay 🙃 This is interesting, I'm just not sure it's going to be very helpful. My concern is that the index will be misunderstood and/or misused by devs. Would love to here you're thoughts, I'm happy to be convinced! |
Hello @rayepps my use case for this is rather simple. It is for building UI, specifically progress bars showing the status for each queue. May I know more about your concern on misuse? |
@UnKnoWn-Consortium My concern is that it feels a little like we're exposing an internal implementation detail that users won't understand unless they look at the code. If an index is going to pass I would expect it to be the index of the item being worked on but this is passing the index of the queue that is doing the processing. I could be wrong BTW, just hesitant |
@rayepps I do agree we are exposing a bit of the internal implementation but it is a useful bit in my opinion.
I think I can implement that. So we will have const users = await parallel(3, userIds, async (userId, index, queueIndex) => {
return await api.users.find(userId)
}) What do you think? |
@UnKnoWn-Consortium you think |
@rayepps I believe they two serve different purposes. The former refers to the position of the item that is being processed in the original array while the latter refers to which queue or parallel pipeline the item is being processed in. Yes the latter can be considered an internal construct of the function but exposing the latter read-only does not hurt. It may be useful to somebody (myself included lol). (P.S. Maybe I should add it to the returned Let me elaborate my use case further. I am using |
stop, I'm blushing
This makes sense. If you can bare with me a bit I'm curious if something like this would work. It's a naive example where you track the state without an index.
|
const results = await parallel(gpuCount, items, async (item) => {
incrementProgress()
// do work on item
incrementComplete()
} Yes this is how I increment the overall progress bar. But without the queue number I cannot have by-queue (or as in this example by-GPU) progress bars. |
…lback functions called in `parallel` while queue index becomes the third argument. test(async): added tests for item index doc(async): updated description and usage for the two new arguments
parallel
are now called with an additional index parameterparallel
are now called with additional item index and queue index arguments
@rayepps I have taken the liberty to add the item index as the second arguments (and the queue index becomes the third) supplied to the async functions called in |
A similar PR (#291) was merged last year so is there any reason this change is not accepted @rayepps ? I really need this and would like to avoid copy/pasting the implementation into my own codebase |
Description
feat(async): added item index as the second argument in the async callback functions called in
parallel
while queue index becomes the third argument.test(async): added tests for item index and queue index
doc(async): updated description and usage for the two new arguments
Checklist
package.json
has been bumped (matching semver)yarn build
command has been run and to update thecdn
directory/docs
directory) has been updatedResolves
Resolves #288