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);
});
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With