I have an async generator function (of a batch job), which got quite big over time. I want to split it into multiple functions :
async *execute(): AsyncGenerator<ISyncState> {
await doThis();
await doThis2();
await doThis3();
yield "this";
await doThis4();
await doThis5();
await doThat();
yield "that";
// .. many more functions
}
async doThis() {...}
async doThat() {...}
async doThis2() {...}
Caller :
const gen = execute();
for await (const syncState of gen)
// do something
I want to turn it into :
async *execute(): AsyncGenerator<ISyncState> {
await step1();
await step2();
await step3();
}
async step1() {
await doThis();
yield "this1"; <-- doesn't work
await doThis2();
yield "this2"; <-- doesn't work
await doThis3();
yield "this3"; <-- doesn't work
}
Is there a way to yield from within "step1()"? (what would be the best way to solve this?)