From 6042b95e65b4c3e78b4577181adf5de4d53ec428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 29 Nov 2022 09:55:19 +0100 Subject: [PATCH] use a class for the fake signal instead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../backend-common/src/context/RootContext.ts | 40 +++++++++---------- packages/backend-tasks/src/tasks/util.test.ts | 2 +- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/backend-common/src/context/RootContext.ts b/packages/backend-common/src/context/RootContext.ts index aa2213ccab..fd3690a945 100644 --- a/packages/backend-common/src/context/RootContext.ts +++ b/packages/backend-common/src/context/RootContext.ts @@ -18,34 +18,32 @@ import { Context } from './types'; /** * Since the root context can never abort, and since nobody is ever meant to - * dispatch events through it, we can use a static fake instance for - * efficiency. + * dispatch events through it, we can use a static fake instance for efficiency. + * + * The reason that this was initially made for the root context is that due to + * the way that we always chain contexts off of it, sometimes a huge number of + * listeners want to add themselves to something that effectively never can be + * aborted in the first place. This triggered warnings that the max listeners + * limit was exceeded. */ -const fakeAbortController = new AbortController(); -const fakeAbortSignal: AbortSignal = Object.freeze( - Object.assign( - { - aborted: false, - reason: undefined, - throwIfAborted() {}, - onabort() {}, - addEventListener() {}, - removeEventListener() {}, - dispatchEvent() { - return true; - }, - }, - fakeAbortController.signal, - ), -); +class FakeAbortSignal implements AbortSignal { + readonly aborted = false; + readonly reason = undefined; + onabort() {} + throwIfAborted() {} + addEventListener() {} + removeEventListener() {} + dispatchEvent() { + return true; + } +} /** * An empty root context. */ export class RootContext implements Context { - readonly abortSignal = fakeAbortSignal; + readonly abortSignal = new FakeAbortSignal(); readonly deadline = undefined; - value(_key: string): T | undefined { return undefined; } diff --git a/packages/backend-tasks/src/tasks/util.test.ts b/packages/backend-tasks/src/tasks/util.test.ts index e17cf1ef1f..e2536abb88 100644 --- a/packages/backend-tasks/src/tasks/util.test.ts +++ b/packages/backend-tasks/src/tasks/util.test.ts @@ -20,7 +20,7 @@ import { delegateAbortController, nowPlus, sleep, validateId } from './util'; class KnexBuilder { public build(client: string): Knex { - return knexFactory({ client }); + return knexFactory({ client, useNullAsDefault: true }); } }