refactor: share extension deferred and runtime helpers

This commit is contained in:
Peter Steinberger
2026-03-14 02:16:19 +00:00
parent 1ac4bac8b1
commit 6a61d5504c
8 changed files with 38 additions and 41 deletions

View File

@@ -8,6 +8,11 @@ type PassiveChannelStatusSnapshot = {
lastProbeAt?: number | null;
};
type TrafficStatusSnapshot = {
lastInboundAt?: number | null;
lastOutboundAt?: number | null;
};
export function buildPassiveChannelStatusSummary<TExtra extends object>(
snapshot: PassiveChannelStatusSnapshot,
extra?: TExtra,
@@ -32,3 +37,12 @@ export function buildPassiveProbedChannelStatusSummary<TExtra extends object>(
lastProbeAt: snapshot.lastProbeAt ?? null,
};
}
export function buildTrafficStatusSummary<TSnapshot extends TrafficStatusSnapshot>(
snapshot?: TSnapshot | null,
) {
return {
lastInboundAt: snapshot?.lastInboundAt ?? null,
lastOutboundAt: snapshot?.lastOutboundAt ?? null,
};
}

View File

@@ -0,0 +1,9 @@
export function createDeferred<T>() {
let resolve!: (value: T | PromiseLike<T>) => void;
let reject!: (reason?: unknown) => void;
const promise = new Promise<T>((res, rej) => {
resolve = res;
reject = rej;
});
return { promise, resolve, reject };
}