db-vendo-client/throttle.js

16 lines
435 B
JavaScript
Raw Normal View History

2018-01-23 15:54:39 +01:00
'use strict'
const throttle = require('p-throttle')
const _request = require('./lib/request')
const withThrottling = (createClient, limit = 5, interval = 1000) => {
const createThrottledClient = (profile, userAgent, request = _request) => {
const throttledRequest = throttle(request, limit, interval)
return createClient(profile, userAgent, throttledRequest)
}
return createThrottledClient
2018-01-23 15:54:39 +01:00
}
module.exports = withThrottling