@typed/fx 0.0.4 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintcache +1 -1
- package/cjs/Cause/Cause.d.ts +10 -0
- package/cjs/Cause/Cause.d.ts.map +1 -1
- package/cjs/Cause/Cause.js +37 -2
- package/cjs/Cause/Cause.js.map +1 -1
- package/cjs/Cause/Renderer.js +1 -1
- package/cjs/Cause/Renderer.js.map +1 -1
- package/cjs/Env/Env.d.ts +9 -1
- package/cjs/Env/Env.d.ts.map +1 -1
- package/cjs/Env/Env.js +32 -5
- package/cjs/Env/Env.js.map +1 -1
- package/cjs/Fiber/fromScope.d.ts +5 -0
- package/cjs/Fiber/fromScope.d.ts.map +1 -0
- package/cjs/Fiber/fromScope.js +17 -0
- package/cjs/Fiber/fromScope.js.map +1 -0
- package/cjs/FiberRef/builtins.d.ts +4 -1
- package/cjs/FiberRef/builtins.d.ts.map +1 -1
- package/cjs/FiberRef/builtins.js +40 -13
- package/cjs/FiberRef/builtins.js.map +1 -1
- package/cjs/FiberRuntime/FiberRuntime.d.ts.map +1 -1
- package/cjs/FiberRuntime/FiberRuntime.js +23 -14
- package/cjs/FiberRuntime/FiberRuntime.js.map +1 -1
- package/cjs/Fx/Fx.d.ts +4 -3
- package/cjs/Fx/Fx.d.ts.map +1 -1
- package/cjs/Fx/Fx.js +25 -24
- package/cjs/Fx/Fx.js.map +1 -1
- package/cjs/Fx/join.d.ts +1 -1
- package/cjs/Fx/join.d.ts.map +1 -1
- package/cjs/Fx/join.js +1 -1
- package/cjs/Fx/join.js.map +1 -1
- package/cjs/Schedule/ScheduleState.d.ts +3 -0
- package/cjs/Schedule/ScheduleState.d.ts.map +1 -1
- package/cjs/Schedule/ScheduleState.js +3 -0
- package/cjs/Schedule/ScheduleState.js.map +1 -1
- package/cjs/Scheduler/RootScheduler.d.ts.map +1 -1
- package/cjs/Scheduler/RootScheduler.js +4 -5
- package/cjs/Scheduler/RootScheduler.js.map +1 -1
- package/cjs/Scheduler/Scheduler.d.ts +2 -2
- package/cjs/Scheduler/Scheduler.d.ts.map +1 -1
- package/cjs/Scheduler/Scheduler.js.map +1 -1
- package/cjs/Scheduler/callbackScheduler.d.ts.map +1 -1
- package/cjs/Scheduler/callbackScheduler.js +1 -0
- package/cjs/Scheduler/callbackScheduler.js.map +1 -1
- package/cjs/Scheduler/runSchedule.d.ts +1 -1
- package/cjs/Scheduler/runSchedule.d.ts.map +1 -1
- package/cjs/Scheduler/runSchedule.js +3 -2
- package/cjs/Scheduler/runSchedule.js.map +1 -1
- package/cjs/Scope/LocalScope.d.ts.map +1 -1
- package/cjs/Scope/LocalScope.js +8 -8
- package/cjs/Scope/LocalScope.js.map +1 -1
- package/cjs/Semaphore/Semaphore.d.ts +9 -9
- package/cjs/Semaphore/Semaphore.d.ts.map +1 -1
- package/cjs/Semaphore/Semaphore.js +34 -15
- package/cjs/Semaphore/Semaphore.js.map +1 -1
- package/cjs/Sink/Sink.d.ts +1 -0
- package/cjs/Sink/Sink.d.ts.map +1 -1
- package/cjs/Sink/Sink.js +11 -1
- package/cjs/Sink/Sink.js.map +1 -1
- package/cjs/Stream/Stream.d.ts +5 -14
- package/cjs/Stream/Stream.d.ts.map +1 -1
- package/cjs/Stream/Stream.js.map +1 -1
- package/cjs/Stream/acquirePermit.d.ts +15 -0
- package/cjs/Stream/acquirePermit.d.ts.map +1 -0
- package/cjs/Stream/acquirePermit.js +43 -0
- package/cjs/Stream/acquirePermit.js.map +1 -0
- package/cjs/Stream/bimap.d.ts +33 -4
- package/cjs/Stream/bimap.d.ts.map +1 -1
- package/cjs/Stream/bimap.js +109 -12
- package/cjs/Stream/bimap.js.map +1 -1
- package/cjs/Stream/continueWith.d.ts +4 -3
- package/cjs/Stream/continueWith.d.ts.map +1 -1
- package/cjs/Stream/continueWith.js +9 -6
- package/cjs/Stream/continueWith.js.map +1 -1
- package/cjs/Stream/delay.d.ts +4 -0
- package/cjs/Stream/delay.d.ts.map +1 -0
- package/cjs/Stream/delay.js +30 -0
- package/cjs/Stream/delay.js.map +1 -0
- package/cjs/Stream/drain.d.ts +2 -2
- package/cjs/Stream/drain.d.ts.map +1 -1
- package/cjs/Stream/drain.js +5 -5
- package/cjs/Stream/drain.js.map +1 -1
- package/cjs/Stream/empty.d.ts.map +1 -1
- package/cjs/Stream/empty.js +1 -2
- package/cjs/Stream/empty.js.map +1 -1
- package/cjs/Stream/flatMap.d.ts +7 -5
- package/cjs/Stream/flatMap.d.ts.map +1 -1
- package/cjs/Stream/flatMap.js +33 -19
- package/cjs/Stream/flatMap.js.map +1 -1
- package/cjs/Stream/flatMapConcurrently.d.ts +6 -0
- package/cjs/Stream/flatMapConcurrently.d.ts.map +1 -0
- package/cjs/Stream/flatMapConcurrently.js +25 -0
- package/cjs/Stream/flatMapConcurrently.js.map +1 -0
- package/cjs/Stream/flatMapFx.d.ts +5 -1
- package/cjs/Stream/flatMapFx.d.ts.map +1 -1
- package/cjs/Stream/flatMapFx.js +18 -3
- package/cjs/Stream/flatMapFx.js.map +1 -1
- package/cjs/Stream/foldMap.d.ts +11 -0
- package/cjs/Stream/foldMap.d.ts.map +1 -0
- package/cjs/Stream/foldMap.js +67 -0
- package/cjs/Stream/foldMap.js.map +1 -0
- package/cjs/Stream/fromArray.d.ts +2 -0
- package/cjs/Stream/fromArray.d.ts.map +1 -0
- package/cjs/Stream/fromArray.js +12 -0
- package/cjs/Stream/fromArray.js.map +1 -0
- package/cjs/Stream/fromCallback.d.ts +4 -3
- package/cjs/Stream/fromCallback.d.ts.map +1 -1
- package/cjs/Stream/fromCallback.js +26 -26
- package/cjs/Stream/fromCallback.js.map +1 -1
- package/cjs/Stream/fromFx.d.ts +23 -8
- package/cjs/Stream/fromFx.d.ts.map +1 -1
- package/cjs/Stream/fromFx.js +36 -16
- package/cjs/Stream/fromFx.js.map +1 -1
- package/cjs/Stream/hkt.d.ts +24 -1
- package/cjs/Stream/hkt.d.ts.map +1 -1
- package/cjs/Stream/hkt.js +43 -5
- package/cjs/Stream/hkt.js.map +1 -1
- package/cjs/Stream/hold.d.ts +27 -0
- package/cjs/Stream/hold.d.ts.map +1 -0
- package/cjs/Stream/hold.js +94 -0
- package/cjs/Stream/hold.js.map +1 -0
- package/cjs/Stream/index.d.ts +14 -1
- package/cjs/Stream/index.d.ts.map +1 -1
- package/cjs/Stream/index.js +14 -1
- package/cjs/Stream/index.js.map +1 -1
- package/cjs/Stream/lazy.d.ts +3 -0
- package/cjs/Stream/lazy.d.ts.map +1 -0
- package/cjs/Stream/lazy.js +9 -0
- package/cjs/Stream/lazy.js.map +1 -0
- package/cjs/Stream/merge.d.ts +18 -0
- package/cjs/Stream/merge.d.ts.map +1 -0
- package/cjs/Stream/merge.js +84 -0
- package/cjs/Stream/merge.js.map +1 -0
- package/cjs/Stream/multicast.d.ts +27 -0
- package/cjs/Stream/multicast.d.ts.map +1 -0
- package/cjs/Stream/multicast.js +83 -0
- package/cjs/Stream/multicast.js.map +1 -0
- package/cjs/Stream/orElse.d.ts +17 -0
- package/cjs/Stream/orElse.d.ts.map +1 -0
- package/cjs/Stream/orElse.js +105 -0
- package/cjs/Stream/orElse.js.map +1 -0
- package/cjs/Stream/periodic.d.ts +1 -1
- package/cjs/Stream/periodic.d.ts.map +1 -1
- package/cjs/Stream/periodic.js +1 -1
- package/cjs/Stream/periodic.js.map +1 -1
- package/cjs/Stream/provide.d.ts +8 -0
- package/cjs/Stream/provide.d.ts.map +1 -0
- package/cjs/Stream/provide.js +42 -0
- package/cjs/Stream/provide.js.map +1 -0
- package/cjs/Stream/run.d.ts +2 -2
- package/cjs/Stream/run.d.ts.map +1 -1
- package/cjs/Stream/run.js +1 -1
- package/cjs/Stream/run.js.map +1 -1
- package/cjs/Stream/scan.d.ts +17 -0
- package/cjs/Stream/scan.d.ts.map +1 -0
- package/cjs/Stream/scan.js +32 -0
- package/cjs/Stream/scan.js.map +1 -0
- package/cjs/Stream/scheduled.d.ts +12 -3
- package/cjs/Stream/scheduled.d.ts.map +1 -1
- package/cjs/Stream/scheduled.js +23 -5
- package/cjs/Stream/scheduled.js.map +1 -1
- package/cjs/Stream/setFiberRefLocally.d.ts +15 -0
- package/cjs/Stream/setFiberRefLocally.d.ts.map +1 -0
- package/cjs/Stream/setFiberRefLocally.js +53 -0
- package/cjs/Stream/setFiberRefLocally.js.map +1 -0
- package/cjs/Stream/skipRepeats.d.ts +5 -0
- package/cjs/Stream/skipRepeats.d.ts.map +1 -0
- package/cjs/Stream/skipRepeats.js +36 -0
- package/cjs/Stream/skipRepeats.js.map +1 -0
- package/cjs/Stream/switchMap.d.ts +18 -0
- package/cjs/Stream/switchMap.d.ts.map +1 -0
- package/cjs/Stream/switchMap.js +124 -0
- package/cjs/Stream/switchMap.js.map +1 -0
- package/cjs/Stream/tap.d.ts +2 -1
- package/cjs/Stream/tap.d.ts.map +1 -1
- package/cjs/Stream/tap.js +4 -2
- package/cjs/Stream/tap.js.map +1 -1
- package/cjs/Supervisor/index.d.ts +2 -0
- package/cjs/Supervisor/index.d.ts.map +1 -1
- package/cjs/Supervisor/index.js +2 -0
- package/cjs/Supervisor/index.js.map +1 -1
- package/cjs/Supervisor/inheritFiberRefs.d.ts +2 -0
- package/cjs/Supervisor/inheritFiberRefs.d.ts.map +1 -0
- package/cjs/Supervisor/inheritFiberRefs.js +17 -0
- package/cjs/Supervisor/inheritFiberRefs.js.map +1 -0
- package/cjs/Timeline/index.js.map +1 -1
- package/esm/Cause/Cause.d.ts +10 -0
- package/esm/Cause/Cause.d.ts.map +1 -1
- package/esm/Cause/Cause.js +27 -0
- package/esm/Cause/Cause.js.map +1 -1
- package/esm/Cause/Renderer.js +1 -1
- package/esm/Cause/Renderer.js.map +1 -1
- package/esm/Env/Env.d.ts +9 -1
- package/esm/Env/Env.d.ts.map +1 -1
- package/esm/Env/Env.js +8 -5
- package/esm/Env/Env.js.map +1 -1
- package/esm/Fiber/fromScope.d.ts +5 -0
- package/esm/Fiber/fromScope.d.ts.map +1 -0
- package/esm/Fiber/fromScope.js +13 -0
- package/esm/Fiber/fromScope.js.map +1 -0
- package/esm/FiberRef/builtins.d.ts +4 -1
- package/esm/FiberRef/builtins.d.ts.map +1 -1
- package/esm/FiberRef/builtins.js +36 -12
- package/esm/FiberRef/builtins.js.map +1 -1
- package/esm/FiberRuntime/FiberRuntime.d.ts.map +1 -1
- package/esm/FiberRuntime/FiberRuntime.js +23 -14
- package/esm/FiberRuntime/FiberRuntime.js.map +1 -1
- package/esm/Fx/Fx.d.ts +4 -3
- package/esm/Fx/Fx.d.ts.map +1 -1
- package/esm/Fx/Fx.js +22 -22
- package/esm/Fx/Fx.js.map +1 -1
- package/esm/Fx/join.d.ts +1 -1
- package/esm/Fx/join.d.ts.map +1 -1
- package/esm/Fx/join.js +1 -1
- package/esm/Fx/join.js.map +1 -1
- package/esm/Schedule/ScheduleState.d.ts +3 -0
- package/esm/Schedule/ScheduleState.d.ts.map +1 -1
- package/esm/Schedule/ScheduleState.js +3 -0
- package/esm/Schedule/ScheduleState.js.map +1 -1
- package/esm/Scheduler/RootScheduler.d.ts.map +1 -1
- package/esm/Scheduler/RootScheduler.js +4 -5
- package/esm/Scheduler/RootScheduler.js.map +1 -1
- package/esm/Scheduler/Scheduler.d.ts +2 -2
- package/esm/Scheduler/Scheduler.d.ts.map +1 -1
- package/esm/Scheduler/Scheduler.js.map +1 -1
- package/esm/Scheduler/callbackScheduler.d.ts.map +1 -1
- package/esm/Scheduler/callbackScheduler.js +1 -0
- package/esm/Scheduler/callbackScheduler.js.map +1 -1
- package/esm/Scheduler/runSchedule.d.ts +1 -1
- package/esm/Scheduler/runSchedule.d.ts.map +1 -1
- package/esm/Scheduler/runSchedule.js +4 -3
- package/esm/Scheduler/runSchedule.js.map +1 -1
- package/esm/Scope/LocalScope.d.ts.map +1 -1
- package/esm/Scope/LocalScope.js +8 -8
- package/esm/Scope/LocalScope.js.map +1 -1
- package/esm/Semaphore/Semaphore.d.ts +9 -9
- package/esm/Semaphore/Semaphore.d.ts.map +1 -1
- package/esm/Semaphore/Semaphore.js +11 -15
- package/esm/Semaphore/Semaphore.js.map +1 -1
- package/esm/Sink/Sink.d.ts +1 -0
- package/esm/Sink/Sink.d.ts.map +1 -1
- package/esm/Sink/Sink.js +10 -1
- package/esm/Sink/Sink.js.map +1 -1
- package/esm/Stream/Stream.d.ts +5 -14
- package/esm/Stream/Stream.d.ts.map +1 -1
- package/esm/Stream/Stream.js.map +1 -1
- package/esm/Stream/acquirePermit.d.ts +15 -0
- package/esm/Stream/acquirePermit.d.ts.map +1 -0
- package/esm/Stream/acquirePermit.js +15 -0
- package/esm/Stream/acquirePermit.js.map +1 -0
- package/esm/Stream/bimap.d.ts +33 -4
- package/esm/Stream/bimap.d.ts.map +1 -1
- package/esm/Stream/bimap.js +102 -11
- package/esm/Stream/bimap.js.map +1 -1
- package/esm/Stream/continueWith.d.ts +4 -3
- package/esm/Stream/continueWith.d.ts.map +1 -1
- package/esm/Stream/continueWith.js +9 -6
- package/esm/Stream/continueWith.js.map +1 -1
- package/esm/Stream/delay.d.ts +4 -0
- package/esm/Stream/delay.d.ts.map +1 -0
- package/esm/Stream/delay.js +26 -0
- package/esm/Stream/delay.js.map +1 -0
- package/esm/Stream/drain.d.ts +2 -2
- package/esm/Stream/drain.d.ts.map +1 -1
- package/esm/Stream/drain.js +6 -6
- package/esm/Stream/drain.js.map +1 -1
- package/esm/Stream/empty.d.ts.map +1 -1
- package/esm/Stream/empty.js +1 -2
- package/esm/Stream/empty.js.map +1 -1
- package/esm/Stream/flatMap.d.ts +7 -5
- package/esm/Stream/flatMap.d.ts.map +1 -1
- package/esm/Stream/flatMap.js +32 -19
- package/esm/Stream/flatMap.js.map +1 -1
- package/esm/Stream/flatMapConcurrently.d.ts +6 -0
- package/esm/Stream/flatMapConcurrently.d.ts.map +1 -0
- package/esm/Stream/flatMapConcurrently.js +19 -0
- package/esm/Stream/flatMapConcurrently.js.map +1 -0
- package/esm/Stream/flatMapFx.d.ts +5 -1
- package/esm/Stream/flatMapFx.d.ts.map +1 -1
- package/esm/Stream/flatMapFx.js +16 -4
- package/esm/Stream/flatMapFx.js.map +1 -1
- package/esm/Stream/foldMap.d.ts +11 -0
- package/esm/Stream/foldMap.d.ts.map +1 -0
- package/esm/Stream/foldMap.js +38 -0
- package/esm/Stream/foldMap.js.map +1 -0
- package/esm/Stream/fromArray.d.ts +2 -0
- package/esm/Stream/fromArray.d.ts.map +1 -0
- package/esm/Stream/fromArray.js +8 -0
- package/esm/Stream/fromArray.js.map +1 -0
- package/esm/Stream/fromCallback.d.ts +4 -3
- package/esm/Stream/fromCallback.d.ts.map +1 -1
- package/esm/Stream/fromCallback.js +26 -26
- package/esm/Stream/fromCallback.js.map +1 -1
- package/esm/Stream/fromFx.d.ts +23 -8
- package/esm/Stream/fromFx.d.ts.map +1 -1
- package/esm/Stream/fromFx.js +24 -14
- package/esm/Stream/fromFx.js.map +1 -1
- package/esm/Stream/hkt.d.ts +24 -1
- package/esm/Stream/hkt.d.ts.map +1 -1
- package/esm/Stream/hkt.js +41 -4
- package/esm/Stream/hkt.js.map +1 -1
- package/esm/Stream/hold.d.ts +27 -0
- package/esm/Stream/hold.d.ts.map +1 -0
- package/esm/Stream/hold.js +66 -0
- package/esm/Stream/hold.js.map +1 -0
- package/esm/Stream/index.d.ts +14 -1
- package/esm/Stream/index.d.ts.map +1 -1
- package/esm/Stream/index.js +14 -1
- package/esm/Stream/index.js.map +1 -1
- package/esm/Stream/lazy.d.ts +3 -0
- package/esm/Stream/lazy.d.ts.map +1 -0
- package/esm/Stream/lazy.js +5 -0
- package/esm/Stream/lazy.js.map +1 -0
- package/esm/Stream/merge.d.ts +18 -0
- package/esm/Stream/merge.d.ts.map +1 -0
- package/esm/Stream/merge.js +55 -0
- package/esm/Stream/merge.js.map +1 -0
- package/esm/Stream/multicast.d.ts +27 -0
- package/esm/Stream/multicast.d.ts.map +1 -0
- package/esm/Stream/multicast.js +55 -0
- package/esm/Stream/multicast.js.map +1 -0
- package/esm/Stream/orElse.d.ts +17 -0
- package/esm/Stream/orElse.d.ts.map +1 -0
- package/esm/Stream/orElse.js +77 -0
- package/esm/Stream/orElse.js.map +1 -0
- package/esm/Stream/periodic.d.ts +1 -1
- package/esm/Stream/periodic.d.ts.map +1 -1
- package/esm/Stream/periodic.js +1 -1
- package/esm/Stream/periodic.js.map +1 -1
- package/esm/Stream/provide.d.ts +8 -0
- package/esm/Stream/provide.d.ts.map +1 -0
- package/esm/Stream/provide.js +13 -0
- package/esm/Stream/provide.js.map +1 -0
- package/esm/Stream/run.d.ts +2 -2
- package/esm/Stream/run.d.ts.map +1 -1
- package/esm/Stream/run.js +2 -2
- package/esm/Stream/run.js.map +1 -1
- package/esm/Stream/scan.d.ts +17 -0
- package/esm/Stream/scan.d.ts.map +1 -0
- package/esm/Stream/scan.js +27 -0
- package/esm/Stream/scan.js.map +1 -0
- package/esm/Stream/scheduled.d.ts +12 -3
- package/esm/Stream/scheduled.d.ts.map +1 -1
- package/esm/Stream/scheduled.js +16 -4
- package/esm/Stream/scheduled.js.map +1 -1
- package/esm/Stream/setFiberRefLocally.d.ts +15 -0
- package/esm/Stream/setFiberRefLocally.d.ts.map +1 -0
- package/esm/Stream/setFiberRefLocally.js +25 -0
- package/esm/Stream/setFiberRefLocally.js.map +1 -0
- package/esm/Stream/skipRepeats.d.ts +5 -0
- package/esm/Stream/skipRepeats.d.ts.map +1 -0
- package/esm/Stream/skipRepeats.js +31 -0
- package/esm/Stream/skipRepeats.js.map +1 -0
- package/esm/Stream/switchMap.d.ts +18 -0
- package/esm/Stream/switchMap.d.ts.map +1 -0
- package/esm/Stream/switchMap.js +95 -0
- package/esm/Stream/switchMap.js.map +1 -0
- package/esm/Stream/tap.d.ts +2 -1
- package/esm/Stream/tap.d.ts.map +1 -1
- package/esm/Stream/tap.js +3 -2
- package/esm/Stream/tap.js.map +1 -1
- package/esm/Supervisor/index.d.ts +2 -0
- package/esm/Supervisor/index.d.ts.map +1 -1
- package/esm/Supervisor/index.js +2 -0
- package/esm/Supervisor/index.js.map +1 -1
- package/esm/Supervisor/inheritFiberRefs.d.ts +2 -0
- package/esm/Supervisor/inheritFiberRefs.d.ts.map +1 -0
- package/esm/Supervisor/inheritFiberRefs.js +14 -0
- package/esm/Supervisor/inheritFiberRefs.js.map +1 -0
- package/esm/Timeline/index.js.map +1 -1
- package/package.json +173 -37
- package/perf/Stream-filter-map-reduce.test.ts +103 -0
- package/readme.md +1 -1
- package/src/Cause/Cause.ts +63 -0
- package/src/Cause/Renderer.ts +1 -1
- package/src/Env/Env.ts +15 -5
- package/src/Fiber/fromScope.ts +19 -0
- package/src/FiberRef/builtins.ts +63 -11
- package/src/FiberRuntime/FiberRuntime.ts +35 -28
- package/src/Fx/Fx.test.ts +2 -2
- package/src/Fx/Fx.ts +11 -10
- package/src/Fx/join.ts +4 -4
- package/src/Schedule/ScheduleState.ts +3 -0
- package/src/Scheduler/RootScheduler.ts +7 -9
- package/src/Scheduler/Scheduler.ts +5 -6
- package/src/Scheduler/callbackScheduler.ts +1 -0
- package/src/Scheduler/runSchedule.ts +5 -2
- package/src/Scope/LocalScope.ts +8 -6
- package/src/Semaphore/Semaphore.ts +12 -19
- package/src/Sink/Sink.ts +11 -1
- package/src/Stream/Stream.ts +9 -15
- package/src/Stream/acquirePermit.ts +32 -0
- package/src/Stream/bimap.ts +164 -12
- package/src/Stream/continueWith.ts +11 -7
- package/src/Stream/delay.ts +43 -0
- package/src/Stream/drain.ts +8 -7
- package/src/Stream/empty.ts +1 -2
- package/src/Stream/flatMap.test.ts +8 -21
- package/src/Stream/flatMap.ts +46 -24
- package/src/Stream/flatMapConcurrently.test.ts +77 -0
- package/src/Stream/flatMapConcurrently.ts +34 -0
- package/src/Stream/flatMapFx.ts +37 -4
- package/src/Stream/foldMap.ts +88 -0
- package/src/Stream/fromArray.ts +8 -0
- package/src/Stream/fromCallback.test.ts +3 -16
- package/src/Stream/fromCallback.ts +48 -29
- package/src/Stream/fromFx.test.ts +3 -24
- package/src/Stream/fromFx.ts +54 -28
- package/src/Stream/hkt.ts +59 -10
- package/src/Stream/hold.test.ts +52 -0
- package/src/Stream/hold.ts +117 -0
- package/src/Stream/index.ts +14 -1
- package/src/Stream/lazy.ts +5 -0
- package/src/Stream/logging.test.ts +8 -3
- package/src/Stream/merge.test.ts +31 -0
- package/src/Stream/merge.ts +76 -0
- package/src/Stream/multicast.test.ts +32 -0
- package/src/Stream/multicast.ts +114 -0
- package/src/Stream/orElse.ts +107 -0
- package/src/Stream/periodic.ts +2 -2
- package/src/Stream/provide.test.ts +78 -0
- package/src/Stream/provide.ts +34 -0
- package/src/Stream/run.ts +6 -3
- package/src/Stream/scan.test.ts +28 -0
- package/src/Stream/scan.ts +46 -0
- package/src/Stream/scheduled.test.ts +9 -1
- package/src/Stream/scheduled.ts +46 -12
- package/src/Stream/setFiberRefLocally.ts +38 -0
- package/src/Stream/skipRepeats.ts +41 -0
- package/src/Stream/switchMap.test.ts +43 -0
- package/src/Stream/switchMap.ts +145 -0
- package/src/Stream/tap.ts +6 -3
- package/src/Supervisor/index.ts +2 -0
- package/src/Supervisor/inheritFiberRefs.ts +17 -0
- package/src/Timeline/index.ts +1 -0
- package/cjs/Effect/Effect.d.ts +0 -199
- package/cjs/Effect/Effect.d.ts.map +0 -1
- package/cjs/Effect/Effect.js +0 -66
- package/cjs/Effect/Effect.js.map +0 -1
- package/cjs/Stream/map.d.ts +0 -14
- package/cjs/Stream/map.d.ts.map +0 -1
- package/cjs/Stream/map.js +0 -30
- package/cjs/Stream/map.js.map +0 -1
- package/cjs/test.d.ts +0 -1
- package/cjs/test.d.ts.map +0 -1
- package/cjs/test.js +0 -2
- package/cjs/test.js.map +0 -1
- package/esm/Effect/Effect.d.ts +0 -199
- package/esm/Effect/Effect.d.ts.map +0 -1
- package/esm/Effect/Effect.js +0 -50
- package/esm/Effect/Effect.js.map +0 -1
- package/esm/Stream/map.d.ts +0 -14
- package/esm/Stream/map.d.ts.map +0 -1
- package/esm/Stream/map.js +0 -25
- package/esm/Stream/map.js.map +0 -1
- package/esm/test.d.ts +0 -1
- package/esm/test.d.ts.map +0 -1
- package/esm/test.js +0 -2
- package/esm/test.js.map +0 -1
- package/src/Effect/Effect.ts +0 -109
- package/src/Stream/map.ts +0 -35
- package/src/test.ts +0 -0
package/src/Stream/flatMap.ts
CHANGED
|
@@ -1,69 +1,91 @@
|
|
|
1
1
|
import { flow, pipe } from 'hkt-ts'
|
|
2
2
|
|
|
3
3
|
import { Stream } from './Stream.js'
|
|
4
|
-
import { MapStream } from './
|
|
4
|
+
import { MapStream } from './bimap.js'
|
|
5
5
|
|
|
6
|
-
import { AtomicCounter, decrement } from '@/Atomic/AtomicCounter.js'
|
|
6
|
+
import { AtomicCounter, decrement, increment } from '@/Atomic/AtomicCounter.js'
|
|
7
7
|
import { Cause } from '@/Cause/index.js'
|
|
8
8
|
import { Env } from '@/Env/Env.js'
|
|
9
9
|
import { FiberContext } from '@/FiberContext/FiberContext.js'
|
|
10
10
|
import { Live } from '@/FiberId/FiberId.js'
|
|
11
11
|
import * as Fx from '@/Fx/index.js'
|
|
12
|
-
import {
|
|
12
|
+
import { access, lazy, unit } from '@/Fx/index.js'
|
|
13
13
|
import { Scheduler } from '@/Scheduler/Scheduler.js'
|
|
14
|
-
import
|
|
14
|
+
import * as Sink from '@/Sink/Sink.js'
|
|
15
|
+
import * as Supervisor from '@/Supervisor/index.js'
|
|
15
16
|
|
|
16
17
|
export function flatMap<A, R2, E2, B>(
|
|
17
18
|
f: (a: A) => Stream<R2, E2, B>,
|
|
19
|
+
__trace?: string,
|
|
18
20
|
): <R, E>(stream: Stream<R, E, A>) => Stream<R | R2, E | E2, B> {
|
|
19
|
-
return (stream) => FlatMapStream.make(stream, f)
|
|
21
|
+
return (stream) => FlatMapStream.make(stream, f, __trace)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function join<R, E, R2, E2, A>(
|
|
25
|
+
stream: Stream<R, E, Stream<R2, E2, A>>,
|
|
26
|
+
__trace?: string,
|
|
27
|
+
): Stream<R | R2, E | E2, A> {
|
|
28
|
+
return flatMap((a: Stream<R2, E2, A>) => a, __trace)(stream)
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
export class FlatMapStream<R, E, A, R2, E2, B> implements Stream<R | R2, E | E2, B> {
|
|
23
|
-
constructor(
|
|
32
|
+
constructor(
|
|
33
|
+
readonly stream: Stream<R, E, A>,
|
|
34
|
+
readonly f: (a: A) => Stream<R2, E2, B>,
|
|
35
|
+
readonly __trace?: string,
|
|
36
|
+
) {}
|
|
24
37
|
|
|
25
|
-
fork<E3>(sink: Sink<E | E2, B, E3>, scheduler: Scheduler, context: FiberContext<Live>) {
|
|
38
|
+
fork<E3>(sink: Sink.Sink<E | E2, B, E3>, scheduler: Scheduler, context: FiberContext<Live>) {
|
|
26
39
|
const { stream, f } = this
|
|
27
40
|
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
41
|
+
return access((env: Env<R | R2>) =>
|
|
42
|
+
stream.fork(
|
|
43
|
+
new FlatMapSink(sink, scheduler, context, f, env, this.__trace),
|
|
44
|
+
scheduler,
|
|
45
|
+
context,
|
|
32
46
|
),
|
|
33
|
-
span('Stream.flatMap'),
|
|
34
47
|
)
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
static make<R, E, A, R2, E2, B>(
|
|
38
51
|
stream: Stream<R, E, A>,
|
|
39
52
|
f: (a: A) => Stream<R2, E2, B>,
|
|
53
|
+
__trace?: string,
|
|
40
54
|
): Stream<R | R2, E | E2, B> {
|
|
41
55
|
if (stream instanceof MapStream) {
|
|
42
|
-
return FlatMapStream.make(stream.stream, flow(stream.f, f))
|
|
56
|
+
return FlatMapStream.make(stream.stream, flow(stream.f, f), __trace)
|
|
43
57
|
}
|
|
44
58
|
|
|
45
|
-
return new FlatMapStream(stream, f)
|
|
59
|
+
return new FlatMapStream(stream, f, __trace)
|
|
46
60
|
}
|
|
47
61
|
}
|
|
48
62
|
|
|
49
|
-
class FlatMapSink<R, E, A, R2, E2, B, E3> implements Sink<E | E2, A, E3> {
|
|
63
|
+
class FlatMapSink<R, E, A, R2, E2, B, E3> implements Sink.Sink<E | E2, A, E3> {
|
|
50
64
|
protected _running = AtomicCounter()
|
|
51
65
|
protected _ended = false
|
|
52
66
|
|
|
53
67
|
constructor(
|
|
54
|
-
readonly sink: Sink<E | E2, B, E3>,
|
|
68
|
+
readonly sink: Sink.Sink<E | E2, B, E3>,
|
|
55
69
|
readonly scheduler: Scheduler,
|
|
56
70
|
readonly context: FiberContext<Live>,
|
|
57
71
|
readonly f: (a: A) => Stream<R2, E2, B>,
|
|
58
72
|
readonly env: Env<R | R2>,
|
|
73
|
+
readonly __trace?: string,
|
|
59
74
|
) {}
|
|
60
75
|
|
|
61
|
-
event = (a: A) =>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
event = (a: A) =>
|
|
77
|
+
Fx.lazy(() => {
|
|
78
|
+
const forked = this.context.fork({
|
|
79
|
+
supervisor: Supervisor.and(Supervisor.inheritFiberRefs)(this.context.supervisor),
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
increment(this._running)
|
|
83
|
+
|
|
84
|
+
return pipe(
|
|
85
|
+
this.f(a).fork(Sink.addTrace(this.innerSink(), this.__trace), this.scheduler, forked),
|
|
86
|
+
Fx.provide(this.env),
|
|
87
|
+
)
|
|
88
|
+
})
|
|
67
89
|
|
|
68
90
|
error = (cause: Cause<E | E2>) => {
|
|
69
91
|
return lazy(() => {
|
|
@@ -82,14 +104,14 @@ class FlatMapSink<R, E, A, R2, E2, B, E3> implements Sink<E | E2, A, E3> {
|
|
|
82
104
|
protected endIfCompleted() {
|
|
83
105
|
return lazy(() => {
|
|
84
106
|
if (this._ended && this._running.get() === 0) {
|
|
85
|
-
this.sink.end
|
|
107
|
+
return this.sink.end
|
|
86
108
|
}
|
|
87
109
|
|
|
88
110
|
return unit
|
|
89
111
|
})
|
|
90
112
|
}
|
|
91
113
|
|
|
92
|
-
protected innerSink(): Sink<E | E2, B, E3> {
|
|
114
|
+
protected innerSink(): Sink.Sink<E | E2, B, E3> {
|
|
93
115
|
return {
|
|
94
116
|
event: this.sink.event,
|
|
95
117
|
error: this.error,
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { deepStrictEqual } from 'assert'
|
|
2
|
+
|
|
3
|
+
import { pipe } from 'hkt-ts'
|
|
4
|
+
import { NonNegativeInteger } from 'hkt-ts/number'
|
|
5
|
+
|
|
6
|
+
import { collectAll } from './_internal.test.js'
|
|
7
|
+
import { flatMapConcurrently } from './flatMapConcurrently.js'
|
|
8
|
+
import { fromCallback } from './fromCallback.js'
|
|
9
|
+
import { merge } from './merge.js'
|
|
10
|
+
|
|
11
|
+
import { testSuite } from '@/_internal/suite.js'
|
|
12
|
+
|
|
13
|
+
testSuite(import.meta.url, () => {
|
|
14
|
+
describe(flatMapConcurrently.name, () => {
|
|
15
|
+
const value = 42
|
|
16
|
+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
17
|
+
|
|
18
|
+
const stream = (level: number) =>
|
|
19
|
+
pipe(
|
|
20
|
+
fromCallback<never, number>(async ({ event, end }) => {
|
|
21
|
+
event(value)
|
|
22
|
+
event(value + 5)
|
|
23
|
+
event(value + 10)
|
|
24
|
+
end()
|
|
25
|
+
}),
|
|
26
|
+
merge(
|
|
27
|
+
fromCallback<never, number>(async ({ event, end }) => {
|
|
28
|
+
event(value + 15)
|
|
29
|
+
event(value + 20)
|
|
30
|
+
end()
|
|
31
|
+
}),
|
|
32
|
+
),
|
|
33
|
+
flatMapConcurrently(
|
|
34
|
+
(a) =>
|
|
35
|
+
fromCallback<never, number>(async ({ event, end }) => {
|
|
36
|
+
event(a + 1)
|
|
37
|
+
await sleep(10)
|
|
38
|
+
event(a + 2)
|
|
39
|
+
end()
|
|
40
|
+
}),
|
|
41
|
+
NonNegativeInteger(level),
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
it('it should control concurrency', async () => {
|
|
46
|
+
const noConcurrency = await collectAll(stream(Infinity))
|
|
47
|
+
|
|
48
|
+
deepStrictEqual(noConcurrency, [
|
|
49
|
+
value + 1,
|
|
50
|
+
value + 5 + 1,
|
|
51
|
+
value + 10 + 1,
|
|
52
|
+
value + 15 + 1,
|
|
53
|
+
value + 20 + 1,
|
|
54
|
+
value + 2,
|
|
55
|
+
value + 5 + 2,
|
|
56
|
+
value + 10 + 2,
|
|
57
|
+
value + 15 + 2,
|
|
58
|
+
value + 20 + 2,
|
|
59
|
+
])
|
|
60
|
+
|
|
61
|
+
const withConcurrency = await collectAll(stream(1))
|
|
62
|
+
|
|
63
|
+
deepStrictEqual(withConcurrency, [
|
|
64
|
+
value + 1,
|
|
65
|
+
value + 2,
|
|
66
|
+
value + 5 + 1,
|
|
67
|
+
value + 5 + 2,
|
|
68
|
+
value + 10 + 1,
|
|
69
|
+
value + 10 + 2,
|
|
70
|
+
value + 15 + 1,
|
|
71
|
+
value + 15 + 2,
|
|
72
|
+
value + 20 + 1,
|
|
73
|
+
value + 20 + 2,
|
|
74
|
+
])
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { flow, pipe } from 'hkt-ts/function'
|
|
2
|
+
import { NonNegativeInteger } from 'hkt-ts/number'
|
|
3
|
+
|
|
4
|
+
import { Stream } from './Stream.js'
|
|
5
|
+
import { acquirePermit } from './acquirePermit.js'
|
|
6
|
+
import { flatMap } from './flatMap.js'
|
|
7
|
+
import { lazy } from './lazy.js'
|
|
8
|
+
|
|
9
|
+
import { Semaphore } from '@/Semaphore/index.js'
|
|
10
|
+
|
|
11
|
+
export function flatMapConcurrently<A, R2, E2, B>(
|
|
12
|
+
f: (a: A) => Stream<R2, E2, B>,
|
|
13
|
+
concurrencyLevel: NonNegativeInteger,
|
|
14
|
+
__trace?: string,
|
|
15
|
+
) {
|
|
16
|
+
return <R, E>(stream: Stream<R, E, A>) =>
|
|
17
|
+
lazy(() => {
|
|
18
|
+
const semaphore = new Semaphore(concurrencyLevel)
|
|
19
|
+
|
|
20
|
+
return pipe(stream, flatMap(flow(f, acquirePermit(semaphore)), __trace))
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function mergeConcurrently(concurrencyLevel: NonNegativeInteger, __trace?: string) {
|
|
25
|
+
return <R, E, R2, E2, A>(stream: Stream<R, E, Stream<R2, E2, A>>) =>
|
|
26
|
+
pipe(
|
|
27
|
+
stream,
|
|
28
|
+
flatMapConcurrently((a) => a, concurrencyLevel, __trace),
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function concatMap<A, R2, E2, B>(f: (a: A) => Stream<R2, E2, B>, __trace?: string) {
|
|
33
|
+
return flow(flatMapConcurrently(f, NonNegativeInteger(1), __trace))
|
|
34
|
+
}
|
package/src/Stream/flatMapFx.ts
CHANGED
|
@@ -1,12 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pipe } from 'hkt-ts/function'
|
|
2
|
+
import { NonNegativeInteger } from 'hkt-ts/number'
|
|
2
3
|
|
|
3
4
|
import { Stream } from './Stream.js'
|
|
4
5
|
import { flatMap } from './flatMap.js'
|
|
5
|
-
import {
|
|
6
|
+
import { flatMapConcurrently } from './flatMapConcurrently.js'
|
|
7
|
+
import { fromFx } from './fromFx.js'
|
|
6
8
|
|
|
7
9
|
import { Fx } from '@/Fx/Fx.js'
|
|
8
10
|
|
|
9
|
-
export function flatMapFx<A, R2, E2, B>(f: (a: A) => Fx<R2, E2, B>,
|
|
11
|
+
export function flatMapFx<A, R2, E2, B>(f: (a: A) => Fx<R2, E2, B>, __trace?: string) {
|
|
10
12
|
return <R, E>(stream: Stream<R, E, A>): Stream<R | R2, E | E2, B> =>
|
|
11
|
-
pipe(
|
|
13
|
+
pipe(
|
|
14
|
+
stream,
|
|
15
|
+
flatMap((a) => fromFx(f(a), __trace), __trace),
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function joinFx<R, E, A>(stream: Stream<R, E, Fx<R, E, A>>, __trace?: string) {
|
|
20
|
+
return pipe(
|
|
21
|
+
stream,
|
|
22
|
+
flatMapFx((x) => x, __trace),
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function flatMapFxConcurrently<A, R2, E2, B>(
|
|
27
|
+
f: (a: A) => Fx<R2, E2, B>,
|
|
28
|
+
concurrencyLevel: NonNegativeInteger,
|
|
29
|
+
__trace?: string,
|
|
30
|
+
) {
|
|
31
|
+
return <R, E>(stream: Stream<R, E, A>): Stream<R | R2, E | E2, B> =>
|
|
32
|
+
pipe(
|
|
33
|
+
stream,
|
|
34
|
+
flatMapConcurrently((a) => fromFx(f(a), __trace), concurrencyLevel, __trace),
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function mergeFxConcurrently(concurrencyLevel: NonNegativeInteger, __trace?: string) {
|
|
39
|
+
return <R, E, R2, E2, A>(stream: Stream<R, E, Fx<R2, E2, A>>) => {
|
|
40
|
+
return pipe(
|
|
41
|
+
stream,
|
|
42
|
+
flatMapFxConcurrently((x) => x, concurrencyLevel, __trace),
|
|
43
|
+
)
|
|
44
|
+
}
|
|
12
45
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Maybe, flow, pipe } from 'hkt-ts'
|
|
2
|
+
import * as Endo from 'hkt-ts/Endomorphism'
|
|
3
|
+
import { Identity } from 'hkt-ts/Typeclass/Identity'
|
|
4
|
+
import * as B from 'hkt-ts/boolean'
|
|
5
|
+
|
|
6
|
+
import { Stream } from './Stream.js'
|
|
7
|
+
import { FilterMapStream, MapStream } from './bimap.js'
|
|
8
|
+
import { observe } from './drain.js'
|
|
9
|
+
import { FromFxStream } from './fromFx.js'
|
|
10
|
+
|
|
11
|
+
import * as Fx from '@/Fx/index.js'
|
|
12
|
+
import { Scheduler } from '@/Scheduler/Scheduler.js'
|
|
13
|
+
|
|
14
|
+
export const filterFoldMap = <A>(I: Identity<A>) => {
|
|
15
|
+
const foldMap_ =
|
|
16
|
+
<B>(f: (b: B) => Maybe.Maybe<A>, __trace?: string) =>
|
|
17
|
+
<R, E>(stream: Stream<R, E, B>): Fx.Fx<R | Scheduler, E, A> => {
|
|
18
|
+
if (stream instanceof FromFxStream) {
|
|
19
|
+
return pipe(
|
|
20
|
+
stream.fx,
|
|
21
|
+
Fx.map(
|
|
22
|
+
flow(
|
|
23
|
+
f,
|
|
24
|
+
Maybe.match(
|
|
25
|
+
() => I.id,
|
|
26
|
+
(a) => I.concat(I.id, a),
|
|
27
|
+
),
|
|
28
|
+
),
|
|
29
|
+
),
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (stream instanceof MapStream) {
|
|
34
|
+
return foldMap_(flow(stream.f, f), __trace)(stream.stream)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (stream instanceof FilterMapStream) {
|
|
38
|
+
return foldMap_(flow(stream.f, Maybe.flatMap(f)), __trace)(stream.stream)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return filterFoldMapStream(I, f, stream, __trace)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return foldMap_
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const foldMap =
|
|
48
|
+
<A>(I: Identity<A>) =>
|
|
49
|
+
<B>(f: (b: B) => A) =>
|
|
50
|
+
filterFoldMap(I)(flow(f, Maybe.Just))
|
|
51
|
+
|
|
52
|
+
const filterFoldMapStream = <A, B, R, E>(
|
|
53
|
+
I: Identity<A>,
|
|
54
|
+
f: (b: B) => Maybe.Maybe<A>,
|
|
55
|
+
stream: Stream<R, E, B>,
|
|
56
|
+
__trace?: string,
|
|
57
|
+
) =>
|
|
58
|
+
Fx.lazy(() => {
|
|
59
|
+
let acc = I.id
|
|
60
|
+
|
|
61
|
+
return pipe(
|
|
62
|
+
stream,
|
|
63
|
+
observe((b) =>
|
|
64
|
+
Fx.fromLazy(() => {
|
|
65
|
+
const maybe = f(b)
|
|
66
|
+
|
|
67
|
+
if (Maybe.isJust(maybe)) {
|
|
68
|
+
acc = I.concat(acc, maybe.value)
|
|
69
|
+
}
|
|
70
|
+
}),
|
|
71
|
+
),
|
|
72
|
+
Fx.flatMap(Fx.join),
|
|
73
|
+
Fx.map(() => acc, __trace),
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
export const reduce = <A, B>(
|
|
78
|
+
f: (a: A, b: B) => A,
|
|
79
|
+
seed: A,
|
|
80
|
+
): (<R, E>(stream: Stream<R, E, B>) => Fx.Fx<Scheduler | R, E, A>) => {
|
|
81
|
+
return flow(
|
|
82
|
+
foldMap(Endo.makeIdentity<A>())((a: B) => (b: A) => f(b, a)),
|
|
83
|
+
Fx.flap(seed),
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const every = foldMap(B.All)
|
|
88
|
+
export const some = foldMap(B.Any)
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { deepStrictEqual } from 'assert'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { collect } from './drain.js'
|
|
3
|
+
import { collectAll } from './_internal.test.js'
|
|
6
4
|
import { fromCallback } from './fromCallback.js'
|
|
7
5
|
|
|
8
|
-
import * as Fx from '@/Fx/index.js'
|
|
9
|
-
import { RootScheduler } from '@/Scheduler/RootScheduler.js'
|
|
10
|
-
import { Scheduler } from '@/Scheduler/Scheduler.js'
|
|
11
6
|
import { testSuite } from '@/_internal/suite.js'
|
|
12
7
|
|
|
13
8
|
testSuite(import.meta.url, () => {
|
|
@@ -20,16 +15,8 @@ testSuite(import.meta.url, () => {
|
|
|
20
15
|
await end()
|
|
21
16
|
})
|
|
22
17
|
|
|
23
|
-
it('
|
|
24
|
-
await
|
|
25
|
-
Fx.Fx(function* () {
|
|
26
|
-
const events: readonly number[] = yield* collect(stream)
|
|
27
|
-
|
|
28
|
-
deepStrictEqual(events, [value, value + 1, value + 2])
|
|
29
|
-
}),
|
|
30
|
-
Fx.provideService(Scheduler, RootScheduler()),
|
|
31
|
-
Fx.runMain,
|
|
32
|
-
)
|
|
18
|
+
it('is collectable', async () => {
|
|
19
|
+
deepStrictEqual(await collectAll(stream), [value, value + 1, value + 2])
|
|
33
20
|
})
|
|
34
21
|
})
|
|
35
22
|
})
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { flow, pipe } from 'hkt-ts'
|
|
2
|
+
import { Left, Right } from 'hkt-ts/Either'
|
|
2
3
|
|
|
3
4
|
import { Stream } from './Stream.js'
|
|
4
5
|
|
|
5
6
|
import { Cause } from '@/Cause/index.js'
|
|
6
|
-
import { Fiber
|
|
7
|
+
import { Fiber } from '@/Fiber/Fiber.js'
|
|
8
|
+
import { fromScope } from '@/Fiber/fromScope.js'
|
|
7
9
|
import { FiberContext } from '@/FiberContext/FiberContext.js'
|
|
8
10
|
import { FiberId } from '@/FiberId/FiberId.js'
|
|
9
|
-
import * as FiberRefs from '@/FiberRefs/FiberRefs.js'
|
|
10
11
|
import { Finalizer } from '@/Finalizer/Finalizer.js'
|
|
11
12
|
import * as Fx from '@/Fx/index.js'
|
|
12
13
|
import { Runtime } from '@/Runtime/Runtime.js'
|
|
13
14
|
import { Scheduler } from '@/Scheduler/Scheduler.js'
|
|
14
|
-
import {
|
|
15
|
-
import { Sink } from '@/Sink/Sink.js'
|
|
16
|
-
import { Exit } from '@/index.js'
|
|
15
|
+
import { Sink, addTrace } from '@/Sink/Sink.js'
|
|
17
16
|
|
|
18
17
|
export interface CallbackSink<E, A> {
|
|
19
18
|
readonly event: (a: A) => Promise<any>
|
|
@@ -21,45 +20,65 @@ export interface CallbackSink<E, A> {
|
|
|
21
20
|
readonly end: () => Promise<any>
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
export function fromCallback<E, A>(
|
|
25
|
-
f:
|
|
23
|
+
export function fromCallback<E = never, A = unknown>(
|
|
24
|
+
f: (sink: CallbackSink<E, A>) => Finalizer | void | Promise<Finalizer | void>,
|
|
25
|
+
__trace?: string,
|
|
26
26
|
): Stream<never, E, A> {
|
|
27
|
-
return new FromCallback<E, A>(f)
|
|
27
|
+
return new FromCallback<E, A>(f, __trace)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export class FromCallback<E, A> implements Stream<never, E, A> {
|
|
31
31
|
constructor(
|
|
32
|
-
readonly f:
|
|
32
|
+
readonly f: (sink: CallbackSink<E, A>) => Finalizer | void | Promise<Finalizer | void>,
|
|
33
|
+
readonly __trace?: string,
|
|
33
34
|
) {}
|
|
34
35
|
|
|
35
36
|
fork = <E2>(
|
|
36
37
|
sink: Sink<E, A, E2>,
|
|
37
38
|
_: Scheduler,
|
|
38
39
|
context: FiberContext<FiberId.Live>,
|
|
39
|
-
): Fx.RIO<never, Fiber<E2, any>> =>
|
|
40
|
-
Fx.
|
|
40
|
+
): Fx.RIO<never, Fiber<E2, any>> => {
|
|
41
|
+
return Fx.lazy(() => {
|
|
42
|
+
const { f, __trace } = this
|
|
43
|
+
|
|
41
44
|
const runtime = Runtime(context)
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
const tracedSink = addTrace(sink, __trace)
|
|
46
|
+
const cbSink: CallbackSink<E, A> = {
|
|
47
|
+
event: flow(tracedSink.event, runtime.run),
|
|
48
|
+
error: (cause) =>
|
|
49
|
+
pipe(
|
|
50
|
+
cause,
|
|
51
|
+
tracedSink.error,
|
|
52
|
+
Fx.tap(() => context.scope.close(Left(cause))),
|
|
53
|
+
runtime.run,
|
|
54
|
+
),
|
|
55
|
+
end: () =>
|
|
56
|
+
pipe(
|
|
57
|
+
tracedSink.end,
|
|
58
|
+
Fx.tap(() => context.scope.close(Right(undefined))),
|
|
59
|
+
runtime.run,
|
|
60
|
+
),
|
|
46
61
|
}
|
|
47
|
-
const finalizer = await this.f(cbSink)
|
|
48
62
|
|
|
49
|
-
|
|
50
|
-
context.
|
|
51
|
-
|
|
63
|
+
const synthetic = fromScope(
|
|
64
|
+
new FiberId.Synthetic([context.id]),
|
|
65
|
+
context.fiberRefs,
|
|
66
|
+
context.scope,
|
|
67
|
+
)
|
|
52
68
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
return pipe(
|
|
70
|
+
Fx.fromPromise(async () => await f(cbSink)),
|
|
71
|
+
Fx.tap(
|
|
72
|
+
(finalizer) =>
|
|
73
|
+
(finalizer &&
|
|
74
|
+
(context.scope.state.tag === 'Open'
|
|
75
|
+
? Fx.fromLazy(() => context.scope.ensuring(finalizer))
|
|
76
|
+
: finalizer(context.scope.state.exit))) ??
|
|
77
|
+
Fx.unit,
|
|
59
78
|
),
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return synthetic
|
|
79
|
+
Fx.fork,
|
|
80
|
+
Fx.map(() => synthetic),
|
|
81
|
+
)
|
|
64
82
|
})
|
|
83
|
+
}
|
|
65
84
|
}
|
|
@@ -1,38 +1,17 @@
|
|
|
1
1
|
import { deepStrictEqual } from 'assert'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { collect, observe } from './drain.js'
|
|
3
|
+
import { collectAll } from './_internal.test.js'
|
|
6
4
|
import { fromFx } from './fromFx.js'
|
|
7
5
|
|
|
8
6
|
import * as Fx from '@/Fx/index.js'
|
|
9
|
-
import { RootScheduler } from '@/Scheduler/RootScheduler.js'
|
|
10
|
-
import { Scheduler } from '@/Scheduler/Scheduler.js'
|
|
11
7
|
|
|
12
8
|
describe(new URL(import.meta.url).pathname, () => {
|
|
13
9
|
describe(fromFx.name, () => {
|
|
14
10
|
const value = Math.random()
|
|
15
11
|
const stream = fromFx(Fx.success(value))
|
|
16
12
|
|
|
17
|
-
it('
|
|
18
|
-
|
|
19
|
-
stream,
|
|
20
|
-
observe((n) => Fx.fromLazy(() => deepStrictEqual(n, value))),
|
|
21
|
-
Fx.flatMap(Fx.join),
|
|
22
|
-
Fx.provideService(Scheduler, RootScheduler()),
|
|
23
|
-
Fx.runMain,
|
|
24
|
-
))
|
|
25
|
-
|
|
26
|
-
it('should be collectable', async () => {
|
|
27
|
-
await pipe(
|
|
28
|
-
Fx.Fx(function* () {
|
|
29
|
-
const events: readonly number[] = yield* collect(stream)
|
|
30
|
-
|
|
31
|
-
deepStrictEqual(events, [value])
|
|
32
|
-
}),
|
|
33
|
-
Fx.provideService(Scheduler, RootScheduler()),
|
|
34
|
-
Fx.runMain,
|
|
35
|
-
)
|
|
13
|
+
it('is collectable', async () => {
|
|
14
|
+
deepStrictEqual(await collectAll(stream), [value])
|
|
36
15
|
})
|
|
37
16
|
})
|
|
38
17
|
})
|
package/src/Stream/fromFx.ts
CHANGED
|
@@ -1,45 +1,71 @@
|
|
|
1
1
|
import { flow, pipe } from 'hkt-ts'
|
|
2
|
+
import { Either } from 'hkt-ts/Either'
|
|
2
3
|
|
|
3
4
|
import { Stream } from './Stream.js'
|
|
4
5
|
|
|
6
|
+
import { Cause } from '@/Cause/Cause.js'
|
|
5
7
|
import { Env } from '@/Env/Env.js'
|
|
8
|
+
import * as Exit from '@/Exit/Exit.js'
|
|
9
|
+
import { FiberContext } from '@/FiberContext/FiberContext.js'
|
|
10
|
+
import { FiberId } from '@/FiberId/index.js'
|
|
6
11
|
import * as Fx from '@/Fx/Fx.js'
|
|
7
|
-
import {
|
|
12
|
+
import { Scheduler } from '@/Scheduler/Scheduler.js'
|
|
13
|
+
import { Sink } from '@/Sink/Sink.js'
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
16
|
* Constructs a Stream from an Fx that runs within a LogSpan enabling
|
|
11
17
|
*/
|
|
12
|
-
export function
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
export function fromFx<R, E, A>(fx: Fx.Fx<R, E, A>, __trace?: string): Stream<R, E, A> {
|
|
19
|
+
return new FromFxStream(fx, __trace)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class FromFxStream<R, E, A> implements Stream<R, E, A> {
|
|
23
|
+
constructor(readonly fx: Fx.Fx<R, E, A>, readonly __trace?: string) {}
|
|
24
|
+
|
|
25
|
+
fork<E2>(sink: Sink<E, A, E2>, scheduler: Scheduler, context: FiberContext<FiberId.Live>) {
|
|
26
|
+
return Fx.asksEnv(
|
|
27
|
+
(env: Env<R>) =>
|
|
28
|
+
scheduler.asap(
|
|
29
|
+
pipe(
|
|
30
|
+
this.fx,
|
|
31
|
+
Fx.matchCause(
|
|
32
|
+
sink.error,
|
|
33
|
+
flow(
|
|
34
|
+
sink.event,
|
|
35
|
+
Fx.flatMap(() => sink.end),
|
|
26
36
|
),
|
|
37
|
+
this.__trace,
|
|
27
38
|
),
|
|
28
|
-
env,
|
|
29
|
-
context,
|
|
30
|
-
span(logSpan),
|
|
31
39
|
),
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
env,
|
|
41
|
+
context,
|
|
42
|
+
),
|
|
43
|
+
this.__trace,
|
|
34
44
|
)
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
|
|
38
|
-
export const
|
|
39
|
-
|
|
40
|
-
export const fromCause =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export const
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
export const now = <A>(value: A, __trace?: string) => fromFx(Fx.now(value), __trace)
|
|
49
|
+
|
|
50
|
+
export const fromCause = <E>(cause: Cause<E>, __trace?: string) =>
|
|
51
|
+
fromFx(Fx.fromCause(cause), __trace)
|
|
52
|
+
|
|
53
|
+
export const fromExit = <E, A>(exit: Exit.Exit<E, A>, __trace?: string) =>
|
|
54
|
+
fromFx(Fx.fromExit(exit), __trace)
|
|
55
|
+
|
|
56
|
+
export const interrupt = (id: FiberId, __trace?: string) => fromExit(Exit.interrupt(id), __trace)
|
|
57
|
+
|
|
58
|
+
export const unexpected = (error: unknown, __trace?: string) =>
|
|
59
|
+
fromExit(Exit.unexpected(error), __trace)
|
|
60
|
+
|
|
61
|
+
export const expected = <E>(error: E, __trace?: string) => fromExit(Exit.expected(error), __trace)
|
|
62
|
+
|
|
63
|
+
export const fromPromise = <A>(promise: () => Promise<A>, __trace?: string) =>
|
|
64
|
+
fromFx(Fx.fromPromise(promise), __trace)
|
|
65
|
+
|
|
66
|
+
export const fromLazy = <A>(lazy: () => A, __trace?: string) => fromFx(Fx.fromLazy(lazy), __trace)
|
|
67
|
+
|
|
68
|
+
export const fromEither = <E, A>(either: Either<E, A>, __trace?: string) =>
|
|
69
|
+
fromFx(Fx.fromEither(either), __trace)
|
|
70
|
+
|
|
71
|
+
export const never = fromFx(Fx.never, 'never')
|