Skip to content

Commit

Permalink
Merge pull request #148 from Financial-Times/no-fetch
Browse files Browse the repository at this point in the history
Support timeouts when using native fetch
  • Loading branch information
ivomurrell authored Oct 16, 2024
2 parents 0f6d1b4 + af1e66b commit 37005c9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ module.exports = EventEmitter => {
// later is discarded within pollers
const _fetch = this.options.retry ? this.eagerFetch : fetch;

return _fetch (this.url, this.options)
const options = {...this.options}
if (options.timeout) {
// add signal option to support native fetch, but keep timeout option
// too to support node-fetch@<2.3.0
options.signal = AbortSignal.timeout(options.timeout)
}

return _fetch (this.url, options)
.then ((response) => {
const latency = new Date () - time;
if (response.ok) {
Expand Down

0 comments on commit 37005c9

Please sign in to comment.