fix(companion): validate waitForIdle timeout option
This commit is contained in:
@@ -661,6 +661,16 @@ describe('CompanionRuntimeClient', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('waitForIdle validates timeoutMs option', () => {
|
||||
const client = new CompanionRuntimeClient({
|
||||
url: 'ws://127.0.0.1:1',
|
||||
});
|
||||
|
||||
expect(() => client.waitForIdle({ timeoutMs: 0 })).toThrow(
|
||||
'timeoutMs must be a positive number',
|
||||
);
|
||||
});
|
||||
|
||||
it('waitForIdle resolves after pending event waiters are cleared', async () => {
|
||||
const client = new CompanionRuntimeClient({
|
||||
url: 'ws://127.0.0.1:1',
|
||||
|
||||
@@ -614,6 +614,10 @@ export class CompanionRuntimeClient {
|
||||
}
|
||||
|
||||
waitForIdle(options?: WaitForIdleOptions): Promise<void> {
|
||||
const timeoutMs = options?.timeoutMs ?? this.requestTimeoutMs;
|
||||
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
||||
throw new Error('timeoutMs must be a positive number');
|
||||
}
|
||||
const pollIntervalMs = options?.pollIntervalMs ?? 25;
|
||||
if (!Number.isFinite(pollIntervalMs) || pollIntervalMs <= 0) {
|
||||
throw new Error('pollIntervalMs must be a positive number');
|
||||
@@ -621,7 +625,6 @@ export class CompanionRuntimeClient {
|
||||
if (!this.hasPendingWork) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
const timeoutMs = options?.timeoutMs ?? this.requestTimeoutMs;
|
||||
const signal = options?.signal;
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user