Comments (2)
I think your implementation may not be the best way to achieve your goal.
Let's see part of your example:
ids.forEach(function(id){
batch.push(function(done){
User.get(id, done);
});
})
Suppose ids.length = 1000000, then you'll be pushing 1000000 functions into batch which then makes 1000000 http calls. Not the best!
Depending on what you're trying to achieve and if you have control over the http end point you're calling, a possible option is to consider redesigning that end point to take a collection/array of ids then you can make a single/fewer calls with subset of ids.
------A look at batch source code ---------
Inside the index.js file you'll find this code segment:
// concurrency
for (var i = 0; i < fns.length; i++) {
if (i == max) break;
next();
}
So when you do batch.push('somefunction')
. it goes into bach.fns -- an array, and here is batch iterating through and executing them sequentially - not parallel execution afterall; javascript as a language does not come with parallel execution out of the box.
This brings me to an idea I haven't given a deep thought and that is making batch or the "concurrency" segment of it asynchronous.
Cheers!
from batch.
Thanks for your thoughtful reply. I didn't use batch in the end but thanks
from batch.
Related Issues (16)
- the parallelism idea in queue.js is neat HOT 1
- Opt to not throw up HOT 2
- unable to use module with browserify HOT 2
- timeout
- New release? HOT 4
- External function doesn't seem to work? HOT 2
- Callbacks called twice when containing errors
- defer function is always `setTimeout` HOT 1
- It would be nice to be able to set 'concurrency' when creating `batch` instance HOT 3
- Better support for ES6 spread operator HOT 1
- Module not found: Error: Can't resolve 'emitter' HOT 1
- Support bundling with `esbuild` HOT 3
- progress percentage
- merge with other batches HOT 1
- everything's broken. nothing works. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from batch.