From ea02fdf6576d9081ed5061aef8ca72a5fe8dfb35 Mon Sep 17 00:00:00 2001 From: nayounsang Date: Sat, 11 Jan 2025 16:43:41 +0900 Subject: [PATCH] feat: worker can clear current handlers --- src/core/SetupApi.ts | 9 +++++++++ src/node/SetupServerApi.ts | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/core/SetupApi.ts b/src/core/SetupApi.ts index e908e5994..b5542fbd9 100644 --- a/src/core/SetupApi.ts +++ b/src/core/SetupApi.ts @@ -13,6 +13,7 @@ export abstract class HandlersController { runtimeHandlers: Array, ): void abstract reset(nextHandles: Array): void + abstract clear(): void abstract currentHandlers(): Array } @@ -36,6 +37,10 @@ export class InMemoryHandlersController implements HandlersController { nextHandlers.length > 0 ? [...nextHandlers] : [...this.initialHandlers] } + public clear(): void { + this.handlers = [] + } + public currentHandlers(): Array { return this.handlers } @@ -107,6 +112,10 @@ export abstract class SetupApi extends Disposable { this.handlersController.reset(nextHandlers) } + public clearHandlers(): void { + this.handlersController.clear() + } + public listHandlers(): ReadonlyArray { return toReadonlyArray(this.handlersController.currentHandlers()) } diff --git a/src/node/SetupServerApi.ts b/src/node/SetupServerApi.ts index 4c86847c8..2a5f275ec 100644 --- a/src/node/SetupServerApi.ts +++ b/src/node/SetupServerApi.ts @@ -42,6 +42,10 @@ class AsyncHandlersController implements HandlersController { nextHandlers.length > 0 ? nextHandlers : context.initialHandlers } + public clear() { + this.context.handlers = [] + } + public currentHandlers(): Array { const { initialHandlers, handlers } = this.context return handlers.concat(initialHandlers)