From 788f4ffe54e37e9a9d6499d98fba106de522260f Mon Sep 17 00:00:00 2001 From: Michael Grosse Huelsewiesche Date: Thu, 21 Sep 2023 19:57:37 -0400 Subject: [PATCH] Using node 14 compatible abort controller --- packages/core/src/callback/index.ts | 3 ++- packages/node/src/lib/abort.ts | 2 +- packages/node/src/lib/token-manager.ts | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core/src/callback/index.ts b/packages/core/src/callback/index.ts index 16f58ae23..936342972 100644 --- a/packages/core/src/callback/index.ts +++ b/packages/core/src/callback/index.ts @@ -1,4 +1,5 @@ import { CoreContext } from '../context' +import { Emitter } from '../emitter' import type { Callback } from '../events' export function pTimeout(promise: Promise, timeout: number): Promise { @@ -18,7 +19,7 @@ export function pTimeout(promise: Promise, timeout: number): Promise { export function sleep( timeoutInMs: number, - signal?: AbortSignal + signal?: { addEventListener(...args: Parameters): void } ): Promise { return new Promise((resolve, reject) => { const timeout = setTimeout(resolve, timeoutInMs) diff --git a/packages/node/src/lib/abort.ts b/packages/node/src/lib/abort.ts index dae0dd341..8eeffdff1 100644 --- a/packages/node/src/lib/abort.ts +++ b/packages/node/src/lib/abort.ts @@ -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 diff --git a/packages/node/src/lib/token-manager.ts b/packages/node/src/lib/token-manager.ts index 28324bec2..0a8fae6d2 100644 --- a/packages/node/src/lib/token-manager.ts +++ b/packages/node/src/lib/token-manager.ts @@ -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