| 471 | * @since 4.0.0 |
| 472 | */ |
| 473 | export 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 |