mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 04:36:04 +00:00
refactor: share extension deferred and runtime helpers
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
9
extensions/shared/deferred.ts
Normal file
9
extensions/shared/deferred.ts
Normal 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 };
|
||||
}
|
||||
Reference in New Issue
Block a user