mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
21 lines
516 B
JavaScript
21 lines
516 B
JavaScript
'use strict'
|
|
|
|
const throttle = require('p-throttle')
|
|
|
|
const _request = require('./lib/request')
|
|
|
|
const withThrottling = (createClient, limit = 5, interval = 1000) => {
|
|
const createThrottledClient = (profile, userAgent, opt = {}) => {
|
|
const request = 'request' in opt ? opt.request : _request
|
|
|
|
const throttledRequest = throttle(request, limit, interval)
|
|
|
|
return createClient(profile, userAgent, {
|
|
...opt,
|
|
request: throttledRequest
|
|
})
|
|
}
|
|
return createThrottledClient
|
|
}
|
|
|
|
module.exports = withThrottling
|