mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 15:24:52 +09:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
dab4dd4a4e
commit
bd609c3c54
4 files changed
+5
-5
No files matched your search
@@ -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<lib.CollectorResult>>;
|
||||
readonly metrics: lib.AsyncHook<[], AsyncIterable<lib.CollectorResult> | void>;
|
||||
|
||||
/**
|
||||
* Called when the controller is shutting down
|
||||
|
||||
@@ -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<lib.CollectorResult>>;
|
||||
readonly metrics: lib.AsyncHook<[], AsyncIterable<lib.CollectorResult> | void>;
|
||||
|
||||
/**
|
||||
* Called when the host is shutting down
|
||||
|
||||
@@ -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<lib.CollectorResult>>;
|
||||
readonly metrics: lib.AsyncHook<[], AsyncIterable<lib.CollectorResult> | void>;
|
||||
|
||||
/**
|
||||
* Called after the Factorio server is started
|
||||
|
||||
@@ -111,7 +111,7 @@ export class AsyncHook<
|
||||
*
|
||||
* Returns all successful results.
|
||||
*/
|
||||
async collect(...args: Args): Promise<Result[]> {
|
||||
async collect(...args: Args): Promise<Exclude<Awaited<Result>, 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> => result !== undefined
|
||||
(result): result is Exclude<Awaited<Result>, void> => result !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user