Skip to content

Commit

Permalink
Using node 14 compatible abort controller
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelGHSeg committed Sep 21, 2023
1 parent 1dd13e4 commit 788f4ff
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/callback/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CoreContext } from '../context'
import { Emitter } from '../emitter'
import type { Callback } from '../events'

export function pTimeout<T>(promise: Promise<T>, timeout: number): Promise<T> {
Expand All @@ -18,7 +19,7 @@ export function pTimeout<T>(promise: Promise<T>, timeout: number): Promise<T> {

export function sleep(
timeoutInMs: number,
signal?: AbortSignal
signal?: { addEventListener(...args: Parameters<Emitter['on']>): void }
): Promise<void> {
return new Promise((resolve, reject) => {
const timeout = setTimeout(resolve, timeoutInMs)
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/lib/abort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AbortSignal {
* This polyfill is only neccessary to support versions of node < 14.17.
* Can be removed once node 14 support is dropped.
*/
class AbortController {
export class AbortController {
signal = new AbortSignal()
abort() {
if (this.signal.aborted) return
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/lib/token-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from './http-client'
import { SignOptions, sign } from 'jsonwebtoken'
import { Emitter, backoff, sleep } from '@segment/analytics-core'
import { AbortSignal, AbortController } from './abort'

type AccessToken = {
access_token: string
Expand Down

0 comments on commit 788f4ff

Please sign in to comment.