Skip to content

Commit

Permalink
remove timers/promises import (nodejs#2665)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and crysmags committed Feb 27, 2024
1 parent 82e2a17 commit 49d5f67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/eventsource/eventsource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const { setTimeout } = require('node:timers/promises')
const { pipeline } = require('node:stream')
const { fetching } = require('../fetch')
const { makeRequest } = require('../fetch/request')
Expand All @@ -11,6 +10,7 @@ const { parseMIMEType } = require('../fetch/dataURL')
const { MessageEvent } = require('../websocket/events')
const { isNetworkError } = require('../fetch/response')
const { getGlobalDispatcher } = require('../global')
const { delay } = require('./util')

let experimentalWarned = false

Expand Down Expand Up @@ -344,7 +344,7 @@ class EventSource extends EventTarget {
this.dispatchEvent(new Event('error'))

// 2. Wait a delay equal to the reconnection time of the event source.
await setTimeout(this.#settings.reconnectionTime, { ref: false })
await delay(this.#settings.reconnectionTime)

// 5. Queue a task to run the following steps:

Expand Down
10 changes: 9 additions & 1 deletion lib/eventsource/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ function isASCIINumber (value) {
return true
}

// https://github.com/nodejs/undici/issues/2664
function delay (ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms).unref()
})
}

module.exports = {
isValidLastEventId,
isASCIINumber
isASCIINumber,
delay
}

0 comments on commit 49d5f67

Please sign in to comment.