()
| 2285 | } |
| 2286 | } |
| 2287 | const next = () => { |
| 2288 | if (todos.length > 0) { |
| 2289 | const a = todos.pop()! |
| 2290 | let index = counter++ |
| 2291 | const returnNextElement = () => { |
| 2292 | const a = todos.pop()! |
| 2293 | index = counter++ |
| 2294 | return core.flatMap(core.yieldNow(), () => |
| 2295 | core.flatMap( |
| 2296 | stepOrExit(restore(f(a, index))), |
| 2297 | onRes |
| 2298 | )) |
| 2299 | } |
| 2300 | const onRes = ( |
| 2301 | res: Exit.Exit<X, E> | Effect.Blocked<X, E> |
| 2302 | ): Effect.Effect<Exit.Exit<X, E> | Effect.Blocked<X, E>, never, R> => { |
| 2303 | if (todos.length > 0) { |
| 2304 | pushResult(res, index) |
| 2305 | if (todos.length > 0) { |
| 2306 | return returnNextElement() |
| 2307 | } |
| 2308 | } |
| 2309 | return core.succeed(res) |
| 2310 | } |
| 2311 | const todo = core.flatMap( |
| 2312 | stepOrExit(restore(f(a, index))), |
| 2313 | onRes |
| 2314 | ) |
| 2315 | const fiber = runFiber(todo) |
| 2316 | startOrder.push(fiber) |
| 2317 | fibers.add(fiber) |
| 2318 | if (interrupted) { |
| 2319 | fiber.currentScheduler.scheduleTask( |
| 2320 | () => { |
| 2321 | fiber.unsafeInterruptAsFork(parent.id()) |
| 2322 | }, |
| 2323 | 0, |
| 2324 | fiber |
| 2325 | ) |
| 2326 | } |
| 2327 | fiber.addObserver((wrapped) => { |
| 2328 | let exit: Exit.Exit<any, any> | core.Blocked |
| 2329 | if (wrapped._op === "Failure") { |
| 2330 | exit = wrapped |
| 2331 | } else { |
| 2332 | exit = wrapped.effect_instruction_i0 as any |
| 2333 | } |
| 2334 | joinOrder.push(fiber) |
| 2335 | fibers.delete(fiber) |
| 2336 | pushResult(exit, index) |
| 2337 | if (results.length === target) { |
| 2338 | resume(core.succeed(Option.getOrElse( |
| 2339 | core.exitCollectAll(collectExits(), { parallel: true }), |
| 2340 | () => core.exitVoid |
| 2341 | ))) |
| 2342 | } else if (residual.length + results.length === target) { |
| 2343 | const exits = collectExits() |
| 2344 | const requests = residual.map((blocked) => blocked.effect_instruction_i0).reduce(RequestBlock_.par) |
no test coverage detected