From bd609c3c544732470f96a568d05b69baa4359f68 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Thu, 8 Oct 2026 05:15:00 +0000 Subject: [PATCH] Allow metrics hook handlers to return nothing A handler that only updates gauges has nothing to yield. collect() already dropped undefined results at runtime, now its type says so too. Co-Authored-By: Claude Opus 5.5 --- packages/controller/src/BaseControllerPlugin.ts | 2 +- packages/host/src/BaseHostPlugin.ts | 2 +- packages/host/src/BaseInstancePlugin.ts | 2 +- packages/lib/src/AsyncHook.ts | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/controller/src/BaseControllerPlugin.ts b/packages/controller/src/BaseControllerPlugin.ts index e515e82d..8a74db3a 100644 --- a/packages/controller/src/BaseControllerPlugin.ts +++ b/packages/controller/src/BaseControllerPlugin.ts @@ -125,7 +125,7 @@ export class ControllerHooks extends lib.AsyncHookCollection { * * @returns an async iterator of prometheus metric results or undefined. */ - readonly metrics: lib.AsyncHook<[], AsyncIterable>; + readonly metrics: lib.AsyncHook<[], AsyncIterable | void>; /** * Called when the controller is shutting down diff --git a/packages/host/src/BaseHostPlugin.ts b/packages/host/src/BaseHostPlugin.ts index 06afe419..32114453 100644 --- a/packages/host/src/BaseHostPlugin.ts +++ b/packages/host/src/BaseHostPlugin.ts @@ -46,7 +46,7 @@ export class HostHooks extends lib.AsyncHookCollection { * * @returns an async iterator of prometheus metric results or undefined. */ - readonly metrics: lib.AsyncHook<[], AsyncIterable>; + readonly metrics: lib.AsyncHook<[], AsyncIterable | void>; /** * Called when the host is shutting down diff --git a/packages/host/src/BaseInstancePlugin.ts b/packages/host/src/BaseInstancePlugin.ts index ac88662e..457c4bbe 100644 --- a/packages/host/src/BaseInstancePlugin.ts +++ b/packages/host/src/BaseInstancePlugin.ts @@ -52,7 +52,7 @@ export class InstanceHooks extends lib.AsyncHookCollection { * * @returns an async iterator of prometheus metric results or undefined. */ - readonly metrics: lib.AsyncHook<[], AsyncIterable>; + readonly metrics: lib.AsyncHook<[], AsyncIterable | void>; /** * Called after the Factorio server is started diff --git a/packages/lib/src/AsyncHook.ts b/packages/lib/src/AsyncHook.ts index a0b8274c..04038da0 100644 --- a/packages/lib/src/AsyncHook.ts +++ b/packages/lib/src/AsyncHook.ts @@ -111,7 +111,7 @@ export class AsyncHook< * * Returns all successful results. */ - async collect(...args: Args): Promise { + async collect(...args: Args): Promise, void>[]> { const results = await Promise.all( [...this._handlers.entries()].map( ([name, handler]) => this._invokeHandler(name, handler, args) @@ -119,7 +119,7 @@ export class AsyncHook< ); return results.filter( - (result): result is Awaited => result !== undefined + (result): result is Exclude, void> => result !== undefined ); }