export function waitForRpcIdle(source, timeout) {
    return new Promise((resolve, reject) => {
        const timer = setTimeout(() => {
            unsubscribe();
            reject(new Error(`Timeout waiting for agent to become idle. Stderr: ${source.getStderr()}`));
        }, timeout);
        const unsubscribe = source.onEvent((event) => {
            if (event.type !== "agent_end")
                return;
            clearTimeout(timer);
            unsubscribe();
            resolve();
        });
    });
}
export function collectRpcEvents(source, timeout) {
    return new Promise((resolve, reject) => {
        const events = [];
        const timer = setTimeout(() => {
            unsubscribe();
            reject(new Error(`Timeout collecting events. Stderr: ${source.getStderr()}`));
        }, timeout);
        const unsubscribe = source.onEvent((event) => {
            events.push(event);
            if (event.type !== "agent_end")
                return;
            clearTimeout(timer);
            unsubscribe();
            resolve(events);
        });
    });
}
//# sourceMappingURL=rpc-client-waits.js.map