| 516 | * @since 4.0.0 |
| 517 | */ |
| 518 | export const fromEffectSchedule = <A, E, R, X, AS extends A, ES, RS>( |
| 519 | effect: Effect.Effect<A, E, R>, |
| 520 | schedule: Schedule.Schedule<X, AS, ES, RS> |
| 521 | ): Stream<A, E | ES, R | RS> => |
| 522 | fromPull(Effect.gen(function*() { |
| 523 | const step = yield* Schedule.toStepWithMetadata(schedule) |
| 524 | let s = yield* Effect.provideService(effect, Schedule.CurrentMetadata, Schedule.CurrentMetadata.defaultValue()) |
| 525 | let initial = true |
| 526 | const pull = Effect.suspend(() => step(s as AS)).pipe( |
| 527 | Effect.flatMap((meta) => Effect.provideService(effect, Schedule.CurrentMetadata, meta)), |
| 528 | Effect.map((next) => { |
| 529 | s = next |
| 530 | return Arr.of(next) |
| 531 | }) |
| 532 | ) as Pull.Pull<Arr.NonEmptyReadonlyArray<A>, E | ES, void, R | RS> |
| 533 | return Effect.suspend(() => { |
| 534 | if (initial) { |
| 535 | initial = false |
| 536 | return Effect.succeed(Arr.of(s)) |
| 537 | } |
| 538 | return pull |
| 539 | }) |
| 540 | })) |
| 541 | |
| 542 | /** |
| 543 | * Creates a stream that emits `void` immediately once, then emits another |