5

I'd like to be able to throttle the calls to getPagerank() to one per second. I've tried various things but can't get it to work.

var pagerank = require('pagerank');
var _ = require('highland');

var urls = [
    'google.com',
    'yahoo.com',
    'bing.com'
];

var getPagerank = _.wrapCallback(pagerank);

// I want to throttle calls to getPagerank to 1/sec
var pageRanks = _(urls)
    .map(getPagerank)
    .merge();

pageRanks.toArray(function(arr) {
    console.log(arr);
});
Jason
  • 11,435
  • 24
  • 77
  • 131

1 Answers1

4

You can use .ratelimit()

e.g. this will limit the stream to processing one item of the array per one second

var _ = require('highland');

_([1,2,3,4]).ratelimit(1, 1000).map(function(x){
  return String(x);
})
.pipe(process.stdout);
Yuri Zarubin
  • 11,439
  • 4
  • 30
  • 33