2018-01-23 15:54:39 +01:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const throttle = require('p-throttle')
|
2020-01-14 23:56:03 +01:00
|
|
|
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) => {
|
2020-01-14 23:56:03 +01:00
|
|
|
// https://github.com/public-transport/hafas-client/issues/76#issuecomment-574408717
|
|
|
|
const {request} = {...defaultProfile, ...profile}
|
2019-02-08 14:59:21 +01:00
|
|
|
|
2019-10-31 18:48:11 +01:00
|
|
|
return {
|
|
|
|
...profile,
|
|
|
|
request: throttle(request, limit, interval)
|
2019-02-08 14:59:21 +01:00
|
|
|
}
|
2018-01-23 15:54:39 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 14:59:21 +01:00
|
|
|
module.exports = withThrottling
|