Code Monkey home page Code Monkey logo

batch's People

Contributors

buschtoens avatar dentfuse avatar dougwilson avatar forbeslindesay avatar matthewmueller avatar michaelsanford avatar nulltask avatar pdehaan avatar r-token avatar razic avatar schne324 avatar stephenmathieson avatar timoxley avatar tj avatar wryk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

batch's Issues

merge with other batches

to produce a single set of progress events, say for example you're resizing images, uploading to s3 etc, you could then combine these batches into one and get a single progress

External function doesn't seem to work?

Why does this code cause the batch to end without doing the jobs?

var Batch = require('batch');

var n = 10;
var batch = new Batch;

batch.concurrency(2);

while (n--) {
    (function(n){
        batch.push(function(done){
            console.log('  start : %s', n);
        arbitrary(done)
        })
    })(n);
}
batch.on('progress', function(e) {
    console.log(e.percent);

});

function arbitrary(done){
    console.log('   done : %s', n);
    done();
}

batch.end();

output is:

  start : 9
   done : -1
10
  start : 8
   done : -1
20
  start : 7
   done : -1
30
  start : 6
   done : -1
40
  start : 5
   done : -1
50
  start : 4
   done : -1
60
  start : 3
   done : -1
70
  start : 2
   done : -1
80
  start : 1
   done : -1
90
  start : 0
   done : -1
100

So the jobs never complete,

timeout

thought on adding a Batch#timeout(1000) or something similar?

unable to use module with browserify

the try/catch dependency on EventEmitter defeats browserify's module resolution. This is one example of why I kept insisting that we should try to have the dependency resolution in component (for example) look the same as node.

I know you'd like to pretend that browserify doesn't exist, but if the stated goal for the module is "Async batch with concurrency control and progress reporting for nodejs and the browser" then one good metric would be whether it works in browserify.

Module not found: Error: Can't resolve 'emitter'

I'm trying to build a file for AWS lambda.
But because batch is required we get the following error:
Module not found: Error: Can't resolve 'emitter'

This is because emitter isn't a dependency in the package.json file.

Btw isn't this code broken???

try {
  var EventEmitter = require('events').EventEmitter;
  if (!EventEmitter) throw new Error();
} catch (err) {
  var Emitter = require('emitter');
}

The event emitter is exported as default:
const EventEmitter = require('events');

Please provide an example of iterating over a a large results array

I tried to use this package to iterate over a large array of results from a database call. I need to make an http request for each result. I gave up in the end. I am using Node 4.2.4.

Please provide an example which iterates over a large array of results and processes them in batches.

Your example:

var Batch = require('batch')
  , batch = new Batch;

batch.concurrency(4);

ids.forEach(function(id){
  batch.push(function(done){
    User.get(id, done);
  });
});

batch.on('progress', function(e){

});

batch.end(function(err, users){

});

Please show the creation of the ids array, what User and users are and where they are defined.

progress percentage

this shouldn't have been the way it is, we should have used an event object with .total, .pending, .percent etc..

Opt to not throw up

In some cases it would be quite useful to make batch collect the errors and not throw up on them. Something like new Batch(dontThrowUp).

var batch = new Batch.throwUp(false);

batch.push(fs.readFile.bind(null, "existing"));
batch.push(fs.readFile.bind(null, "non-existing"));
batch.push(fs.readFile.bind(null, "existing"));

batch.end(function(err, res) {
  console.log(err); // [null, Error, null]
  console.log(res) // [Buffer, null, Buffer]
});

Callbacks called twice when containing errors

When the callback provided to batch.end throws an error things can go a bit haywire... Here is an example I put together.

const Batch = require('batch')
const batch = new Batch()

batch.push(cb => cb())
batch.push(cb => cb())
batch.push(cb => cb())

var i = 1;

batch.end(function(err) {
  console.log(i++)

  if(err) {
    console.log(err)
  }

  throw "Error"
})

Outputs

1
2
Error

This shows the callback being called twice, once with no error (expected) and once with the error contained in the callback! After doing a bit of digging I found the try/catch block in index.js:117 to be the culprit. I assume this was put in so that synchronous type functions would produce callback style errors. It's a really messy bug to have though because it can catch all downstream errors of the callback.

Better support for ES6 spread operator

Heya,

Currently, some of the code for this library looks like:

Batch.prototype.push = function(fn){
  this.fns.push(fn);
  return this;
};

which means I have to do something like....

const requests = [(done) => { done(); }, (done) => { done(); }];
requests.forEach(request => batch.push(request));

but I expect to be able to:

const requests = [(done) => { done(); }, (done) => { done(); }];
batch.fns.push(...requests);

I would like a couple of things:

  1. It's not clear if fns is able to be accessed publicly. If it is, then maybe just remove the public method altogether. If not, maybe consider enhancing the method to support spread operations.

  2. If things are to stay as they are - consider renaming public method away from push since it doesn't function quite the same as Array.prototype.push. I did not find this intuitive.

New release?

I know it's old, but it's nice a simple. New release with a repo at least? ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.