Skip to content
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

fix: correctly handle parallel downloading #348

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

qkdreyer
Copy link

No description provided.

@qkdreyer qkdreyer requested a review from a team as a code owner August 20, 2024 15:14
@qkdreyer
Copy link
Author

const promise = delay => new Promise(resolve => setTimeout(() => console.log(delay) || resolve(delay), delay))
const chunkify = (arr, n) => arr.reduce((acc, cur, i) => {
  const index = Math.floor(i / n)
  acc[index] = [...(acc[index] || []), cur]
  return acc;
}, [])
for (let chunk of chunkify([promise(3000), promise(2500), promise(1500)], 2)) await Promise.all(chunk)

1500
2500
3000

for (let chunk of chunkify([() => promise(3000), () => promise(2500), () => promise(1500)], 2)) await Promise.all(chunk.map(fn => fn()))

2500
3000
1500

Copy link

@NomadsComputerllc NomadsComputerllc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewing changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants