-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathexample.js
37 lines (33 loc) · 858 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict'
const request = require('superagent')
const _ = require('lodash')
const Throttle = require('./index')
// create throttle instance
let throttle = new Throttle({
// start unpaused
active: true,
// send max 5 requests every `ratePer` ms
rate: 5,
// send max `rate` requests every 10000 ms
ratePer: 4000,
// max 2 requests should run concurrently
concurrent: 4
})
_.times(10, function(idx) {
request
.get('placekitten.com/100/' + (100 + idx))
.use(throttle.plugin('foo'))
.end(function(err, res) {
console.log(err ? err : 'serial ' + idx)
})
console.log('added ' + idx)
})
_.times(10, function(idx) {
request
.get('placekitten.com/100/' + (100 + idx))
.use(throttle.plugin())
.end(function(err, res) {
console.log(err ? err : 'res ' + idx)
})
console.log('added ' + idx)
})