mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-11-02 08:35:24 +00:00
feat: convert tmux monitoring into a plugin (B10)
This commit is contained in:
1 parent
79d77678c9
commit
708eedb861
145 files changed
+30308
-4458
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { runAdaptivePolling } from "@termix/plugin-sdk/ui";
|
||||
|
||||
type AdaptivePollResult = boolean | void;
|
||||
|
||||
interface AdaptivePollingPolicy {
|
||||
minIntervalMs: number;
|
||||
maxIntervalMs: number;
|
||||
stablePollsPerStep?: number;
|
||||
jitterRatio?: number;
|
||||
maxRequestDutyCycle?: number;
|
||||
}
|
||||
|
||||
export function useAdaptivePolling(
|
||||
poll: () => AdaptivePollResult | Promise<AdaptivePollResult>,
|
||||
policy: AdaptivePollingPolicy,
|
||||
enabled = true,
|
||||
options: {
|
||||
runImmediately?: boolean;
|
||||
onError?: (error: unknown) => void;
|
||||
} = {},
|
||||
): void {
|
||||
const pollRef = useRef(poll);
|
||||
const errorRef = useRef(options.onError);
|
||||
pollRef.current = poll;
|
||||
errorRef.current = options.onError;
|
||||
const {
|
||||
minIntervalMs,
|
||||
maxIntervalMs,
|
||||
stablePollsPerStep,
|
||||
jitterRatio,
|
||||
maxRequestDutyCycle,
|
||||
} = policy;
|
||||
const runImmediately = options.runImmediately;
|
||||
|
||||
useEffect(
|
||||
() =>
|
||||
runAdaptivePolling(
|
||||
() => pollRef.current(),
|
||||
{
|
||||
minIntervalMs,
|
||||
maxIntervalMs,
|
||||
stablePollsPerStep,
|
||||
jitterRatio,
|
||||
maxRequestDutyCycle,
|
||||
},
|
||||
{
|
||||
enabled: () => enabled,
|
||||
runImmediately,
|
||||
onError: (error) => errorRef.current?.(error),
|
||||
},
|
||||
),
|
||||
[
|
||||
enabled,
|
||||
jitterRatio,
|
||||
maxIntervalMs,
|
||||
minIntervalMs,
|
||||
runImmediately,
|
||||
stablePollsPerStep,
|
||||
maxRequestDutyCycle,
|
||||
],
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user