diff --git a/lib/api-event-iterator.js b/lib/api-event-iterator.js index 4012d6948..1b2b55bf1 100644 --- a/lib/api-event-iterator.js +++ b/lib/api-event-iterator.js @@ -1,10 +1,12 @@ -import {on} from 'node:events'; - export async function * asyncEventIteratorFromApi(api) { - for await (const [plan] of on(api, 'run')) { + // TODO: support multiple runs (watch mode) + const {value: plan} = await api.events('run').next(); + + for await (const stateChange of plan.status.events('stateChange')) { + yield stateChange; - for await (const [stateChange] of on(plan.status, 'stateChange')) { - yield stateChange; + if (stateChange.type === 'end' || stateChange.type === 'interrupt') { + break; } } }