Skip to content

Instantly share code, notes, and snippets.

@sintaxi
Last active December 14, 2015 01:39
Show Gist options
  • Save sintaxi/5007744 to your computer and use it in GitHub Desktop.
Save sintaxi/5007744 to your computer and use it in GitHub Desktop.
Async compatible Batch and Retry api requirements.
var batcher = require("batcher")
var myUploader = function(item, done){
uploadSomewhere(item, function(err, result){
done(err, result)
})
}
var myErrCheck = function(err, retry, pass){
if(err.statusCode == 503){
retry()
}else{
pass()
}
}
batcher.batch(["item1", "item2", "item3"], myUploader, { batchSize: 4, errFn: myErrCheck }, function(err, results){
if(err){
// we failed even after retrys
}else{
// all tasks are successful
}
})
@sintaxi
Copy link
Author

sintaxi commented Feb 21, 2013

Third argument should be optional in which case it would default to batch size of 4 and perform no retries.

Third argument could also be a function in which case the batch size would default to 4.

Third argument could also be an integer in which case the batch size would change to value passed in and no retries would be performed.

@sintaxi
Copy link
Author

sintaxi commented Feb 21, 2013

It appears that async's eachLimit() is half of what we want. Just need to build an array of items to retry.

https://github.com/caolan/async#eachlimitarr-limit-iterator-callback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment