MCPcopy Create free account
hub / github.com/Effect-TS/effect / next

Function next

packages/effect/src/internal/fiberRuntime.ts:2287–2366  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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)

Callers 2

forEachConcurrentDiscardFunction · 0.70
checkFunction · 0.70

Calls 14

restoreFunction · 0.85
runFiberFunction · 0.85
pushResultFunction · 0.85
collectExitsFunction · 0.85
forEachConcurrentDiscardFunction · 0.85
checkFunction · 0.85
resumeFunction · 0.70
addMethod · 0.65
scheduleTaskMethod · 0.65
unsafeInterruptAsForkMethod · 0.65
idMethod · 0.65
addObserverMethod · 0.65

Tested by

no test coverage detected