MCPcopy Index your code
hub / github.com/Effect-TS/effect / next

Function next

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

Source from the content-addressed store, hash-verified

2275 }
2276 }
2277 const next = () => {
2278 if (todos.length > 0) {
2279 const a = todos.pop()!
2280 let index = counter++
2281 const returnNextElement = () => {
2282 const a = todos.pop()!
2283 index = counter++
2284 return core.flatMap(core.yieldNow(), () =>
2285 core.flatMap(
2286 stepOrExit(restore(f(a, index))),
2287 onRes
2288 ))
2289 }
2290 const onRes = (
2291 res: Exit.Exit<X, E> | Effect.Blocked<X, E>
2292 ): Effect.Effect<Exit.Exit<X, E> | Effect.Blocked<X, E>, never, R> => {
2293 if (todos.length > 0) {
2294 pushResult(res, index)
2295 if (todos.length > 0) {
2296 return returnNextElement()
2297 }
2298 }
2299 return core.succeed(res)
2300 }
2301 const todo = core.flatMap(
2302 stepOrExit(restore(f(a, index))),
2303 onRes
2304 )
2305 const fiber = runFiber(todo)
2306 startOrder.push(fiber)
2307 fibers.add(fiber)
2308 if (interrupted) {
2309 fiber.currentScheduler.scheduleTask(
2310 () => {
2311 fiber.unsafeInterruptAsFork(parent.id())
2312 },
2313 0,
2314 fiber
2315 )
2316 }
2317 fiber.addObserver((wrapped) => {
2318 let exit: Exit.Exit<any, any> | core.Blocked
2319 if (wrapped._op === "Failure") {
2320 exit = wrapped
2321 } else {
2322 exit = wrapped.effect_instruction_i0 as any
2323 }
2324 joinOrder.push(fiber)
2325 fibers.delete(fiber)
2326 pushResult(exit, index)
2327 if (results.length === target) {
2328 resume(core.succeed(Option.getOrElse(
2329 core.exitCollectAll(collectExits(), { parallel: true }),
2330 () => core.exitVoid
2331 )))
2332 } else if (residual.length + results.length === target) {
2333 const exits = collectExits()
2334 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