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

Function repeatLoop

packages/effect/src/Channel.ts:3399–3421  ·  view source on GitHub ↗
(
  self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
  onExit: (exit: Exit.Exit<OutDone, OutErr>, scope: Scope.Scope) => Pull.Pull<void, E, OutDone2, R>
)

Source from the content-addressed store, hash-verified

3397 ))
3398
3399const repeatLoop = <OutElem, OutErr, OutDone, InElem, InErr, InDone, Env, E, OutDone2, R>(
3400 self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>,
3401 onExit: (exit: Exit.Exit<OutDone, OutErr>, scope: Scope.Scope) => Pull.Pull<void, E, OutDone2, R>
3402): Channel<OutElem, E, OutDone2, InElem, InErr, InDone, Env | R> =>
3403 fromTransform((upstream, scope) =>
3404 Effect.sync(() => {
3405 let currentPull: Pull.Pull<OutElem, E, OutDone2, Env | R> | undefined
3406 const makePull = (): Pull.Pull<OutElem, E, OutDone2, Env | R> => {
3407 const runScope = Scope.forkUnsafe(scope)
3408 return Effect.flatMap(toTransform(self)(upstream, runScope), (pull) => {
3409 currentPull = Effect.catchCause(pull, (cause) => {
3410 const exit = Pull.doneExitFromCause(cause) as Exit.Exit<OutDone, OutErr>
3411 return Scope.close(runScope, exit).pipe(
3412 Effect.flatMap(() => onExit(exit, scope)),
3413 Effect.flatMap(makePull)
3414 )
3415 })
3416 return currentPull
3417 })
3418 }
3419 return Effect.suspend(() => currentPull ?? makePull())
3420 })
3421 )
3422
3423/**
3424 * Repeats this channel forever.

Callers 2

Channel.tsFile · 0.85
foreverFunction · 0.85

Calls 3

fromTransformFunction · 0.70
makePullFunction · 0.70
syncMethod · 0.45

Tested by

no test coverage detected