Skip to content

Commit

Permalink
feat: worker can clear current handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
nayounsang committed Jan 11, 2025
1 parent e3234fd commit ea02fdf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/SetupApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export abstract class HandlersController {
runtimeHandlers: Array<RequestHandler | WebSocketHandler>,
): void
abstract reset(nextHandles: Array<RequestHandler | WebSocketHandler>): void
abstract clear(): void
abstract currentHandlers(): Array<RequestHandler | WebSocketHandler>
}

Expand All @@ -36,6 +37,10 @@ export class InMemoryHandlersController implements HandlersController {
nextHandlers.length > 0 ? [...nextHandlers] : [...this.initialHandlers]
}

public clear(): void {
this.handlers = []
}

public currentHandlers(): Array<RequestHandler | WebSocketHandler> {
return this.handlers
}
Expand Down Expand Up @@ -107,6 +112,10 @@ export abstract class SetupApi<EventsMap extends EventMap> extends Disposable {
this.handlersController.reset(nextHandlers)
}

public clearHandlers(): void {
this.handlersController.clear()
}

public listHandlers(): ReadonlyArray<RequestHandler | WebSocketHandler> {
return toReadonlyArray(this.handlersController.currentHandlers())
}
Expand Down
4 changes: 4 additions & 0 deletions src/node/SetupServerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class AsyncHandlersController implements HandlersController {
nextHandlers.length > 0 ? nextHandlers : context.initialHandlers
}

public clear() {
this.context.handlers = []
}

public currentHandlers(): Array<RequestHandler | WebSocketHandler> {
const { initialHandlers, handlers } = this.context
return handlers.concat(initialHandlers)
Expand Down

0 comments on commit ea02fdf

Please sign in to comment.