sodiray / radash

Functional utility library - modern, simple, typed, powerful
https://radash-docs.vercel.app
MIT License
4.1k stars 160 forks source link

feat: add option to run parallel in order #371

Closed Fjandin closed 2 months ago

Fjandin commented 8 months ago

Description

Adds an extra optional option to the parallel method {executeInOrder?: boolean}

Example

const userIds = [1, 2, 3, 4, 5]
const users = await parallel(3, userIds, async (userId) => {
  return await api.users.find(userId)
}, {executeInOrder: true})

Checklist

vercel[bot] commented 8 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
radash-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 12, 2023 9:08am
sodiray commented 6 months ago

@Fjandin thanks for the PR 🙏 It's possible I'm missing something but isn't executing the functions in order make it the opposite of executing them in parallel? Could you just not use the parallel function?

sodiray commented 6 months ago

On second look at the PR I see, they're still parallel but in order... still a bit confused tho. I'm curious, what's your use case?

Fjandin commented 2 months ago

@sodiray Sorry for the late reply. Some time since, so don't remember the details, but had a weird case where i needed the tasks to be picked out in order. However now that I look at it again, I can see i could just as well just reverse the array of tasks :P And yeah, the fact that I guess the order shouldn't really matter in parallel execution. I'm just gonna close it. I can see this is a unnecessary complexion to add. Have a nice day :)