db-vendo-client/throttle.js
2020-01-14 23:56:48 +01:00

16 lines
422 B
JavaScript

'use strict'
const throttle = require('p-throttle')
const defaultProfile = require('./lib/default-profile')
const withThrottling = (profile, limit = 5, interval = 1000) => {
// https://github.com/public-transport/hafas-client/issues/76#issuecomment-574408717
const {request} = {...defaultProfile, ...profile}
return {
...profile,
request: throttle(request, limit, interval)
}
}
module.exports = withThrottling