[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
42
components/connectHostsStaggered.ts
Normal file
42
components/connectHostsStaggered.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Schedule a batch of host connections across separate frames instead of all
|
||||
* at once.
|
||||
*
|
||||
* Connecting many hosts in a single synchronous pass mounts every terminal in
|
||||
* one React commit, so each terminal's `createXTermRuntime()` (which spins up a
|
||||
* live WebGL context) runs back-to-back on the main thread and freezes the UI
|
||||
* until the whole batch finishes. Staggering lets the first tab paint
|
||||
* immediately and gives the renderer room to breathe between mounts.
|
||||
*
|
||||
* The first target connects synchronously so a tab shows up without delay; the
|
||||
* rest are deferred one `stepMs` apart. `schedule` is injectable for testing.
|
||||
*/
|
||||
export type StaggerScheduler = (callback: () => void, delayMs: number) => void;
|
||||
|
||||
export interface ConnectHostsStaggeredOptions {
|
||||
/** Gap between successive deferred connections, in ms. */
|
||||
stepMs?: number;
|
||||
/** Defers a callback; defaults to setTimeout. */
|
||||
schedule?: StaggerScheduler;
|
||||
}
|
||||
|
||||
const defaultSchedule: StaggerScheduler = (callback, delayMs) => {
|
||||
setTimeout(callback, delayMs);
|
||||
};
|
||||
|
||||
export function connectHostsStaggered<T>(
|
||||
targets: T[],
|
||||
onConnect: (target: T) => void,
|
||||
options: ConnectHostsStaggeredOptions = {},
|
||||
): void {
|
||||
const stepMs = options.stepMs ?? 90;
|
||||
const schedule = options.schedule ?? defaultSchedule;
|
||||
|
||||
targets.forEach((target, index) => {
|
||||
if (index === 0) {
|
||||
onConnect(target);
|
||||
} else {
|
||||
schedule(() => onConnect(target), index * stepMs);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user