task generator function
task resolving to generator's return type
compound task execution is interrupted only at yield statements, so despite returning immediately any promise-based chains would continue running until the first yield
due to type unpredictability you HAVE to use .generator()
together with yield* to avoid type issues, despite the fact that task may be yielded directly
const task = Task.generate(function*() {
try {
const value1 = yield* delayedValueTask('data', 400).generator();
const value2 = yield* delayedValueTask(value1.length, 300).generator();
return value2;
} catch (e) {
return -1;
}
});
Generated using TypeDoc
Create compound task from generator function
Applying yield to task within the generator function awaits the task and returns underlying value in case of success However the convinient option for typescript is to use
yield* task.generator()
as othervise one may have to deal with union typesIn case of failure an error is thrown and may be caught by try-catch
If error is not caught the task is interrupted and returns 'just left error' immediately. In case of cancelation the task is interrupted and returns 'nothing' immediately