From 13894ff94a2e5d058534f6e4c8886f5fe7fb4453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Thu, 24 Jun 2021 16:30:30 +0200 Subject: [PATCH] ref: Leave only valid buffer implementation --- packages/utils/src/promisebuffer.ts | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/utils/src/promisebuffer.ts b/packages/utils/src/promisebuffer.ts index 033c40d18c51..5ba47670a5c6 100644 --- a/packages/utils/src/promisebuffer.ts +++ b/packages/utils/src/promisebuffer.ts @@ -1,9 +1,6 @@ import { SentryError } from './error'; -import { isThenable } from './is'; import { SyncPromise } from './syncpromise'; -type TaskProducer = () => PromiseLike; - /** A simple queue that holds promises. */ export class PromiseBuffer { /** Internal set of queued Promises */ @@ -21,22 +18,14 @@ export class PromiseBuffer { /** * Add a promise to the queue. * - * @param taskProducer A function producing any PromiseLike; In previous versions this used to be `@param task: PromiseLike`, however, Promises were instantly created on the call-site, making them fall through the buffer limit. + * @param taskProducer A function producing any PromiseLike. * @returns The original promise. */ - public add(taskProducer: PromiseLike | TaskProducer): PromiseLike { - // NOTE: This is necessary to preserve backwards compatibility - // It should accept _only_ `TaskProducer` but we dont want to break other custom transports - // that are utilizing our `Buffer` implementation. - // see: https://github.com/getsentry/sentry-javascript/issues/3725 - const normalizedTaskProducer: TaskProducer = isThenable(taskProducer) - ? () => taskProducer as PromiseLike - : (taskProducer as TaskProducer); - + public add(taskProducer: () => PromiseLike): PromiseLike { if (!this.isReady()) { return SyncPromise.reject(new SentryError('Not adding Promise due to buffer limit reached.')); } - const task = normalizedTaskProducer(); + const task = taskProducer(); if (this._buffer.indexOf(task) === -1) { this._buffer.push(task); }