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

Function fromEffectSchedule

packages/effect/src/Stream.ts:473–495  ·  view source on GitHub ↗
(
  effect: Effect.Effect<A, E, R>,
  schedule: Schedule.Schedule<X, AS, ES, RS>
)

Source from the content-addressed store, hash-verified

471 * @since 4.0.0
472 */
473export const fromEffectSchedule = <A, E, R, X, AS extends A, ES, RS>(
474 effect: Effect.Effect<A, E, R>,
475 schedule: Schedule.Schedule<X, AS, ES, RS>
476): Stream<A, E | ES, R | RS> =>
477 fromPull(Effect.gen(function*() {
478 const step = yield* Schedule.toStepWithMetadata(schedule)
479 let s = yield* Effect.provideService(effect, Schedule.CurrentMetadata, Schedule.CurrentMetadata.defaultValue())
480 let initial = true
481 const pull = Effect.suspend(() => step(s as AS)).pipe(
482 Effect.flatMap((meta) => Effect.provideService(effect, Schedule.CurrentMetadata, meta)),
483 Effect.map((next) => {
484 s = next
485 return Arr.of(next)
486 })
487 ) as Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E | ES, void, R | RS>
488 return Effect.suspend(() => {
489 if (initial) {
490 initial = false
491 return Effect.succeed(Arr.of(s))
492 }
493 return pull
494 })
495 }))
496
497/**
498 * Creates a stream that emits `void` immediately once, then emits another

Callers

nothing calls this directly

Calls 6

fromPullFunction · 0.70
stepFunction · 0.70
pipeMethod · 0.65
ofMethod · 0.65
mapMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected