keep your pants on, async requests

#Keep your pants on, javascript. ###don't blow your stack, or over-async a nice web service.

slow is smooth, smooth is fast.

it goes,

 npm install slow
slow.walk( [1,2,3,4], random_wait, console.log);//results, in order 
function random_wait(icallback){
  setTimeout(callbck(i), Math.random()*4000);

unlike the ___other woderful async libraries___, this one lets you set the pace.

so you don't immediately do everything at once.

###like some fool.

you can be safe with memory and respect external services. #the methods are:

##rate-limited explicitly set a pace, but respect a maximum current request rate (defaults to 10)

(it begins at this pace, but slows it down if callbacks begin to build-up)

  • slow.pace ( arr, fn, [options], callback ) //60bpm
  • slow.walk ( arr, fn, [options], callback ) //120bpm
  • slow.jog ( arr, fn, [options], callback ) //150bpm
  • ( arr, fn, [options], callback ) //180bpm
  • slow.heartbeat ( arr, fn, [options], callback ) //72bpm

##count-limited do only a few things at a time. (only go as fast as your callback does)

  • slow.steady ( arr, fn, [options], callback ) //max=5
  • slow.handful ( arr, fn, [options], callback ) //max=3
  • slow.pocket ( arr, fn, [options], callback ) //max=7
  • slow.backpack ( arr, fn, [options], callback ) //max=15
  • slow.shovel ( arr, fn, [options], callback ) //max=35

##the options are:

 debug: true, //understand when the requests are being fired 
 verbose: true, //include the input in the results 
 monitorfunction(r){console.log(r.length)}, //watch the results coming in in real-time 
 max: 10 //the most number of concurrent requests you're comfortable making 

but you can just ignore those tho

##in the f-ing Browzers!1 (2.8k)

<script src=""></script>
  slow.__walk__( [1,2,3,4,5,6,7], my_function, {max:3}, function(r){
  function my_function(qcallback){
    var x=Math.floor(Math.random()*2000)
    setTimeout(function(){callback("finished "+q+" in "+x+"ms")}, x)

##what about my craziness.. if you're in a situation that needs fancy paramaters, wrap them up like this:

slow.steady( [1,2,3,4], whatev, console.log);
function whatev(icallback){
  my_craziness(param1, param2, then_finally, a, callback) //works fine 

or if your function returns [errror, result] (i hate that)

slow.steady( [1,2,3,4], whatev, console.log);
function whatev(icallback){
  my_craziness(i, function(errresult){
    callback(result||err);//la de da;)