db-vendo-client/throttle.js

17 lines
424 B
JavaScript
Raw Permalink Normal View History

2018-01-23 15:54:39 +01:00
'use strict'
const throttle = require('p-throttle')
const defaultProfile = require('./lib/default-profile')
2018-01-23 15:54:39 +01:00
2019-10-31 18:48:11 +01:00
const withThrottling = (profile, limit = 5, interval = 1000) => {
// https://github.com/public-transport/hafas-client/issues/76#issuecomment-574408717
const {request} = {...defaultProfile, ...profile}
2019-10-31 18:48:11 +01:00
return {
...profile,
2021-06-28 23:33:05 +02:00
request: throttle({limit, interval})(request)
}
2018-01-23 15:54:39 +01:00
}
module.exports = withThrottling