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

Process items in batches similar to better-queue. #43

Open
tbreeding opened this issue Mar 29, 2021 · 2 comments
Open

Process items in batches similar to better-queue. #43

tbreeding opened this issue Mar 29, 2021 · 2 comments

Comments

@tbreeding
Copy link

tbreeding commented Mar 29, 2021

I saw some other closed issue on batching, but it didn't seem to related directly to this.

Basically, the better queue implementation is that it takes in individual items, but passes them to the process function in an array, but then outputs the results individually in the original order.

https://www.npmjs.com/package/better-queue#batch-processing

What are your thoughts on implementing something like this?

The use case is where it's more efficient to make a call to an API with multiple items than it is with each individual items.

Queue.push('1')
Queue.push('2')
Queue.push('3')

function (userIds: string[]) {
    const response = await request.post('/users/likes', { users_ids: userIds })
    // POST /users/likes` `{ user_ids: ['1', '2', '3']` <= Response `{ 1: { likes: 5 }, 2: { likes: 3 }, 3: { likes: 12 } }
   const likes = []
   for (const id of userIds) likes.push(response.body[id])

   return likes
}

This saves API calls and carries (typically) an overall speed benefit as making one request with multiple entries takes less total time than each call made individually.

@mcollina
Copy link
Owner

This would be a really nice feature to add. It's similar to _writev() in Node.js streams.

How would you implement it?

@tbreeding
Copy link
Author

I need to take a look into. Sorry. Busy busy.

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

No branches or pull requests

2 participants