Fork Join
spawn(...) forks work and wait(...) joins the returned futures.
function* loadPage() {
const header = yield* spawn(function* loadHeader() {
yield* sleep(1000);
return "header";
});
const sidebar = yield* spawn(function* loadSidebar() {
yield* sleep(2000);
return "sidebar";
});
return {
header: yield* wait(header),
sidebar: yield* wait(sidebar),
};
}loadPage starts loadHeader and loadSidebar as separate processes.
loadPage waits for both futures before returning the combined page result.