@typed/fx 0.0.4 → 0.0.6
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.js +1 -1
- 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/FiberContext/FiberContext.js +1 -1
- package/cjs/FiberContext/FiberContext.js.map +1 -1
- package/cjs/FiberRef/builtins.d.ts.map +1 -1
- package/cjs/FiberRef/builtins.js +6 -6
- package/cjs/FiberRef/builtins.js.map +1 -1
- package/cjs/FiberRuntime/FiberRuntime.d.ts.map +1 -1
- package/cjs/FiberRuntime/FiberRuntime.js +22 -13
- package/cjs/FiberRuntime/FiberRuntime.js.map +1 -1
- package/cjs/Fx/Fx.d.ts +3 -2
- package/cjs/Fx/Fx.d.ts.map +1 -1
- package/cjs/Fx/Fx.js +24 -22
- 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 -10
- 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 +5 -4
- package/cjs/Stream/bimap.d.ts.map +1 -1
- package/cjs/Stream/bimap.js +11 -9
- 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/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 +43 -17
- package/cjs/Stream/flatMap.js.map +1 -1
- package/cjs/Stream/flatMapConcurrently.d.ts +5 -0
- package/cjs/Stream/flatMapConcurrently.d.ts.map +1 -0
- package/cjs/Stream/flatMapConcurrently.js +20 -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/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 +14 -8
- package/cjs/Stream/fromFx.d.ts.map +1 -1
- package/cjs/Stream/fromFx.js +24 -15
- package/cjs/Stream/fromFx.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 +8 -0
- package/cjs/Stream/index.d.ts.map +1 -1
- package/cjs/Stream/index.js +8 -0
- 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/map.d.ts +4 -3
- package/cjs/Stream/map.d.ts.map +1 -1
- package/cjs/Stream/map.js +11 -8
- package/cjs/Stream/map.js.map +1 -1
- 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 +118 -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/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 +51 -0
- package/cjs/Stream/setFiberRefLocally.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 +136 -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/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.js +1 -1
- 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/FiberContext/FiberContext.js +1 -1
- package/esm/FiberContext/FiberContext.js.map +1 -1
- package/esm/FiberRef/builtins.d.ts.map +1 -1
- package/esm/FiberRef/builtins.js +6 -6
- package/esm/FiberRef/builtins.js.map +1 -1
- package/esm/FiberRuntime/FiberRuntime.d.ts.map +1 -1
- package/esm/FiberRuntime/FiberRuntime.js +22 -13
- package/esm/FiberRuntime/FiberRuntime.js.map +1 -1
- package/esm/Fx/Fx.d.ts +3 -2
- package/esm/Fx/Fx.d.ts.map +1 -1
- package/esm/Fx/Fx.js +21 -20
- 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 -10
- 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 +5 -4
- package/esm/Stream/bimap.d.ts.map +1 -1
- package/esm/Stream/bimap.js +11 -9
- 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/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 +43 -18
- package/esm/Stream/flatMap.js.map +1 -1
- package/esm/Stream/flatMapConcurrently.d.ts +5 -0
- package/esm/Stream/flatMapConcurrently.d.ts.map +1 -0
- package/esm/Stream/flatMapConcurrently.js +15 -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/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 +14 -8
- package/esm/Stream/fromFx.d.ts.map +1 -1
- package/esm/Stream/fromFx.js +13 -13
- package/esm/Stream/fromFx.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 +8 -0
- package/esm/Stream/index.d.ts.map +1 -1
- package/esm/Stream/index.js +8 -0
- 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/map.d.ts +4 -3
- package/esm/Stream/map.d.ts.map +1 -1
- package/esm/Stream/map.js +11 -8
- package/esm/Stream/map.js.map +1 -1
- 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 +90 -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/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 +23 -0
- package/esm/Stream/setFiberRefLocally.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 +107 -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/Timeline/index.js.map +1 -1
- package/package.json +111 -21
- package/readme.md +1 -1
- package/src/Cause/Cause.ts +63 -0
- package/src/Cause/Renderer.ts +1 -1
- package/src/Env/Env.ts +1 -1
- package/src/Fiber/fromScope.ts +19 -0
- package/src/FiberContext/FiberContext.ts +1 -1
- package/src/FiberRef/builtins.ts +19 -10
- package/src/FiberRuntime/FiberRuntime.ts +32 -25
- package/src/Fx/Fx.test.ts +2 -2
- package/src/Fx/Fx.ts +10 -9
- 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 -11
- package/src/Stream/acquirePermit.ts +32 -0
- package/src/Stream/bimap.ts +16 -9
- package/src/Stream/continueWith.ts +11 -7
- 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 +58 -23
- package/src/Stream/flatMapConcurrently.test.ts +77 -0
- package/src/Stream/flatMapConcurrently.ts +30 -0
- package/src/Stream/flatMapFx.ts +37 -4
- 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 +47 -30
- package/src/Stream/hold.test.ts +52 -0
- package/src/Stream/hold.ts +117 -0
- package/src/Stream/index.ts +8 -0
- package/src/Stream/lazy.ts +5 -0
- package/src/Stream/logging.test.ts +8 -3
- package/src/Stream/map.ts +25 -11
- 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 +123 -0
- package/src/Stream/periodic.ts +2 -2
- 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 +44 -0
- package/src/Stream/switchMap.test.ts +43 -0
- package/src/Stream/switchMap.ts +159 -0
- package/src/Stream/tap.ts +6 -3
- 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/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/src/Effect/Effect.ts +0 -109
package/src/Fx/Fx.test.ts
CHANGED
|
@@ -107,14 +107,14 @@ describe(new URL(import.meta.url).pathname, () => {
|
|
|
107
107
|
console.time('Fx: Fib25 Construction')
|
|
108
108
|
const program = fib(25)
|
|
109
109
|
console.timeEnd('Fx: Fib25 Construction')
|
|
110
|
-
for (let i = 0; i <
|
|
110
|
+
for (let i = 0; i < 5; i++) {
|
|
111
111
|
console.time('Fib25')
|
|
112
112
|
await runMain(program)
|
|
113
113
|
console.timeEnd('Fib25')
|
|
114
114
|
}
|
|
115
115
|
})
|
|
116
116
|
|
|
117
|
-
it('runs Fib w/ generators', async () => {
|
|
117
|
+
it.skip('runs Fib w/ generators', async () => {
|
|
118
118
|
const fib = (n: number): Fx.Of<number> =>
|
|
119
119
|
Fx.Fx(function* () {
|
|
120
120
|
if (n < 2) {
|
package/src/Fx/Fx.ts
CHANGED
|
@@ -206,6 +206,9 @@ export const tap =
|
|
|
206
206
|
__trace,
|
|
207
207
|
)
|
|
208
208
|
|
|
209
|
+
export const tapLazy = <A, B>(f: (a: A) => B, __trace?: string) =>
|
|
210
|
+
tap((a: A) => fromLazy(() => f(a)), __trace)
|
|
211
|
+
|
|
209
212
|
export const mapTo =
|
|
210
213
|
<B>(b: B, __trace?: string) =>
|
|
211
214
|
<R, E, A>(fx: Fx<R, E, A>): Fx<R, E, B> =>
|
|
@@ -227,13 +230,7 @@ export const match =
|
|
|
227
230
|
__trace?: string,
|
|
228
231
|
) =>
|
|
229
232
|
<R>(fx: Fx<R, E, A>): Fx<R | R2 | R3, E2 | E3, B | C> =>
|
|
230
|
-
Match.make(
|
|
231
|
-
fx,
|
|
232
|
-
(cause) =>
|
|
233
|
-
cause.tag === 'Expected' ? onLeft(cause.error) : (fromCause(cause) as Fx<R2, E2, B>),
|
|
234
|
-
onRight,
|
|
235
|
-
__trace,
|
|
236
|
-
)
|
|
233
|
+
Match.make(fx, flow(findExpectedCause, Either.match(onLeft, fromCause)), onRight, __trace)
|
|
237
234
|
|
|
238
235
|
export const orElseCause =
|
|
239
236
|
<E, R2, E2, B>(onLeft: (cause: Cause.Cause<E>) => Fx<R2, E2, B>, __trace?: string) =>
|
|
@@ -601,8 +598,12 @@ export const CommutativeBoth: CB.CommutativeBoth3<FxHKT> = {
|
|
|
601
598
|
both,
|
|
602
599
|
}
|
|
603
600
|
|
|
604
|
-
export const zipLeft = AB.zipLeft<FxHKT>({ ...CommutativeBoth, ...Covariant })
|
|
605
|
-
|
|
601
|
+
export const zipLeft = AB.zipLeft<FxHKT>({ ...CommutativeBoth, ...Covariant }) as <R2, E2, B>(
|
|
602
|
+
second: Fx<R2, E2, B>,
|
|
603
|
+
) => <R, E, A>(first: Fx<R, E, A>) => Fx<R | R2, E | E2, A>
|
|
604
|
+
export const zipRight = AB.zipRight<FxHKT>({ ...CommutativeBoth, ...Covariant }) as <R2, E2, B>(
|
|
605
|
+
second: Fx<R2, E2, B>,
|
|
606
|
+
) => <R, E, A>(first: Fx<R, E, A>) => Fx<R | R2, E | E2, B>
|
|
606
607
|
|
|
607
608
|
export const IdentityBothPar: IB.IdentityBoth3<FxHKT> = {
|
|
608
609
|
...CommutativeBoth,
|
package/src/Fx/join.ts
CHANGED
|
@@ -18,10 +18,10 @@ export const join = <E, A>(fiber: Fiber.Fiber<E, A>) =>
|
|
|
18
18
|
),
|
|
19
19
|
)
|
|
20
20
|
|
|
21
|
-
export const forkJoinInContext =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
export const forkJoinInContext =
|
|
22
|
+
(context: FiberContext<FiberId.Live>) =>
|
|
23
|
+
<R, E, A>(fx: Fx.Fx<R, E, A>): Fx.Fx<R, E, A> =>
|
|
24
|
+
pipe(fx, Fx.forkInContext(context), Fx.flatMap(join))
|
|
25
25
|
|
|
26
26
|
export const forkJoinIn = <R, E, A>(fx: Fx.Fx<R, E, A>, scope: Scope): Fx.Fx<R, E, A> =>
|
|
27
27
|
pipe(fx, Fx.forkIn(scope), Fx.flatMap(join))
|
|
@@ -20,6 +20,9 @@ const maxTimeAssociative = Time.makeAssociative({
|
|
|
20
20
|
})
|
|
21
21
|
const maybeMaxTimeAssociative = makeAssociative(maxTimeAssociative)
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* TODO: ScheduleState should track Exit values to allow exiting early w/ custom logic
|
|
25
|
+
*/
|
|
23
26
|
export class ScheduleState {
|
|
24
27
|
constructor(
|
|
25
28
|
/**
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { identity } from 'hkt-ts'
|
|
2
|
-
|
|
3
1
|
import { Scheduler } from './Scheduler.js'
|
|
4
2
|
import { callbackScheduler } from './callbackScheduler.js'
|
|
5
3
|
import { runSchedule } from './runSchedule.js'
|
|
@@ -18,6 +16,7 @@ import { complete } from '@/Future/complete.js'
|
|
|
18
16
|
import { wait } from '@/Future/wait.js'
|
|
19
17
|
import { Fx } from '@/Fx/Fx.js'
|
|
20
18
|
import { Schedule } from '@/Schedule/Schedule.js'
|
|
19
|
+
import { ScheduleState } from '@/Schedule/ScheduleState.js'
|
|
21
20
|
import { Delay } from '@/Time/index.js'
|
|
22
21
|
import { SetTimeoutTimer } from '@/Timer/SetTimeoutTimer.js'
|
|
23
22
|
import { Timer } from '@/Timer/Timer.js'
|
|
@@ -45,15 +44,14 @@ class RootSchedulerImpl implements Scheduler {
|
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
readonly asap: Scheduler['asap'] = <R, E, A
|
|
47
|
+
readonly asap: Scheduler['asap'] = <R, E, A>(
|
|
49
48
|
fx: Fx<R, E, A>,
|
|
50
49
|
env: Env<R>,
|
|
51
50
|
context: FiberContext<FiberId.Live>,
|
|
52
|
-
|
|
53
|
-
): Live<E2, B> => {
|
|
51
|
+
): Live<E, A> => {
|
|
54
52
|
setFiberRef(CurrentEnv, env)(context.fiberRefs)
|
|
55
53
|
|
|
56
|
-
const runtime = new FiberRuntime(this.runAt(
|
|
54
|
+
const runtime = new FiberRuntime(this.runAt(fx, Delay(0)), context)
|
|
57
55
|
|
|
58
56
|
// Safe to call sync since it will be run by the Timeline.
|
|
59
57
|
runtime.startSync()
|
|
@@ -61,17 +59,17 @@ class RootSchedulerImpl implements Scheduler {
|
|
|
61
59
|
return runtime
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
readonly schedule: Scheduler['schedule'] = <R, E, A,
|
|
62
|
+
readonly schedule: Scheduler['schedule'] = <R, E, A, B>(
|
|
65
63
|
fx: Fx<R, E, A>,
|
|
66
64
|
env: Env<R>,
|
|
67
65
|
schedule: Schedule,
|
|
68
66
|
context: FiberContext<FiberId.Live>,
|
|
69
|
-
|
|
67
|
+
onEnd?: (state: ScheduleState) => Fx<R, E, B>,
|
|
70
68
|
) => {
|
|
71
69
|
setFiberRef(CurrentEnv, env)(context.fiberRefs)
|
|
72
70
|
|
|
73
71
|
const runtime = new FiberRuntime(
|
|
74
|
-
runSchedule(
|
|
72
|
+
runSchedule(fx, schedule, this.timer, this.runAt, onEnd),
|
|
75
73
|
context,
|
|
76
74
|
)
|
|
77
75
|
|
|
@@ -9,20 +9,19 @@ import { ScheduleState } from '@/Schedule/ScheduleState.js'
|
|
|
9
9
|
import { Service } from '@/Service/Service.js'
|
|
10
10
|
|
|
11
11
|
export interface Scheduler extends Disposable {
|
|
12
|
-
readonly asap: <R, E, A
|
|
12
|
+
readonly asap: <R, E, A>(
|
|
13
13
|
fx: Fx<R, E, A>,
|
|
14
14
|
env: Env<R>,
|
|
15
15
|
context: FiberContext<FiberId.Live>,
|
|
16
|
-
|
|
17
|
-
) => Live<E2, B>
|
|
16
|
+
) => Live<E, A>
|
|
18
17
|
|
|
19
|
-
readonly schedule: <R, E, A,
|
|
18
|
+
readonly schedule: <R, E, A, B>(
|
|
20
19
|
fx: Fx<R, E, A>,
|
|
21
20
|
env: Env<R>,
|
|
22
21
|
schedule: Schedule,
|
|
23
22
|
context: FiberContext<FiberId.Live>,
|
|
24
|
-
|
|
25
|
-
) => Live<
|
|
23
|
+
onEnd?: (state: ScheduleState) => Fx<R, E, B>,
|
|
24
|
+
) => Live<E, ScheduleState>
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
export const Scheduler = Service<Scheduler>('Scheduler')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Clock from '@/Clock/Clock.js'
|
|
2
|
-
import { Fx } from '@/Fx/Fx.js'
|
|
2
|
+
import { Fx, unit } from '@/Fx/Fx.js'
|
|
3
3
|
import { Schedule } from '@/Schedule/Schedule.js'
|
|
4
4
|
import { ScheduleState } from '@/Schedule/ScheduleState.js'
|
|
5
5
|
import { Delay } from '@/Time/index.js'
|
|
@@ -7,11 +7,12 @@ import { Delay } from '@/Time/index.js'
|
|
|
7
7
|
/**
|
|
8
8
|
* Runs an Fx on a given Schedule
|
|
9
9
|
*/
|
|
10
|
-
export function runSchedule<R, E, A>(
|
|
10
|
+
export function runSchedule<R, E, A, B>(
|
|
11
11
|
fx: Fx<R, E, A>,
|
|
12
12
|
schedule: Schedule,
|
|
13
13
|
clock: Clock.Clock,
|
|
14
14
|
runAt: (fx: Fx<R, E, A>, delay: Delay) => Fx<R, E, A>,
|
|
15
|
+
onEnd?: (state: ScheduleState) => Fx<R, E, B>,
|
|
15
16
|
): Fx<R, E, ScheduleState> {
|
|
16
17
|
return Fx(function* () {
|
|
17
18
|
let [state, decision] = schedule.step(clock.getCurrentTime(), new ScheduleState())
|
|
@@ -26,6 +27,8 @@ export function runSchedule<R, E, A>(
|
|
|
26
27
|
decision = nextDecision
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
yield* onEnd?.(state) ?? unit
|
|
31
|
+
|
|
29
32
|
// Return the final state
|
|
30
33
|
return state
|
|
31
34
|
})
|
package/src/Scope/LocalScope.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { mapTo } from 'hkt-ts/Either'
|
|
|
2
2
|
import * as Maybe from 'hkt-ts/Maybe'
|
|
3
3
|
import { First } from 'hkt-ts/Typeclass/Associative'
|
|
4
4
|
import { pipe } from 'hkt-ts/function'
|
|
5
|
-
import { NonNegativeInteger } from 'hkt-ts/number'
|
|
6
5
|
|
|
7
6
|
import { Closeable } from './Closeable.js'
|
|
8
7
|
import { ReleaseMap } from './ReleaseMap.js'
|
|
@@ -18,7 +17,7 @@ const { concat: concatExits } = makeSequentialAssociative<any, any>(First)
|
|
|
18
17
|
export class LocalScope implements Closeable {
|
|
19
18
|
protected _state: ScopeState = Open
|
|
20
19
|
protected _releaseMap = new ReleaseMap(this.strategy)
|
|
21
|
-
protected _refCount = AtomicCounter(
|
|
20
|
+
protected _refCount = AtomicCounter()
|
|
22
21
|
protected _exit: Maybe.Maybe<Exit<any, any>> = Maybe.Nothing
|
|
23
22
|
|
|
24
23
|
constructor(readonly strategy: FinalizationStrategy) {}
|
|
@@ -44,9 +43,12 @@ export class LocalScope implements Closeable {
|
|
|
44
43
|
|
|
45
44
|
const extended = new LocalScope(strategy)
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
extended.ensuring(() => {
|
|
47
|
+
decrement(this._refCount)
|
|
48
|
+
|
|
49
|
+
return this.release
|
|
50
|
+
})
|
|
51
|
+
|
|
50
52
|
increment(this._refCount)
|
|
51
53
|
|
|
52
54
|
return extended
|
|
@@ -64,7 +66,7 @@ export class LocalScope implements Closeable {
|
|
|
64
66
|
// Internals
|
|
65
67
|
|
|
66
68
|
protected release = lazy(() => {
|
|
67
|
-
if (
|
|
69
|
+
if (this._refCount.get() > 0 || Maybe.isNothing(this._exit) || this.isClosed) {
|
|
68
70
|
return success(false)
|
|
69
71
|
}
|
|
70
72
|
|
|
@@ -4,7 +4,7 @@ import { NonNegativeInteger } from 'hkt-ts/number'
|
|
|
4
4
|
import { AtomicCounter, decrement, increment } from '@/Atomic/AtomicCounter.js'
|
|
5
5
|
import { MutableFutureQueue } from '@/Future/MutableFutureQueue.js'
|
|
6
6
|
import { wait } from '@/Future/wait.js'
|
|
7
|
-
import
|
|
7
|
+
import * as Fx from '@/Fx/Fx.js'
|
|
8
8
|
import { fiberScoped, managed, scoped } from '@/Fx/scoped.js'
|
|
9
9
|
|
|
10
10
|
export class Semaphore {
|
|
@@ -22,10 +22,10 @@ export class Semaphore {
|
|
|
22
22
|
return this.running.get()
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
readonly prepare = fromLazy(() => {
|
|
25
|
+
readonly prepare = Fx.fromLazy(() => {
|
|
26
26
|
if (this.available > 0) {
|
|
27
27
|
return new Acquisition(
|
|
28
|
-
fromLazy(() => {
|
|
28
|
+
Fx.fromLazy(() => {
|
|
29
29
|
increment(this.running)
|
|
30
30
|
}),
|
|
31
31
|
this.release,
|
|
@@ -39,11 +39,7 @@ export class Semaphore {
|
|
|
39
39
|
const acquisition = new Acquisition(
|
|
40
40
|
pipe(
|
|
41
41
|
wait(future),
|
|
42
|
-
|
|
43
|
-
fromLazy(() => {
|
|
44
|
-
increment(that.running)
|
|
45
|
-
}),
|
|
46
|
-
),
|
|
42
|
+
Fx.tapLazy(() => increment(that.running)),
|
|
47
43
|
),
|
|
48
44
|
this.release,
|
|
49
45
|
)
|
|
@@ -51,17 +47,14 @@ export class Semaphore {
|
|
|
51
47
|
return acquisition
|
|
52
48
|
})
|
|
53
49
|
|
|
54
|
-
protected release = fromLazy(() => {
|
|
50
|
+
protected release = Fx.fromLazy(() => {
|
|
55
51
|
decrement(this.running)
|
|
56
|
-
|
|
57
|
-
if (this.waiting.size() > 0) {
|
|
58
|
-
this.waiting.next(unit)
|
|
59
|
-
}
|
|
52
|
+
this.waiting.next(Fx.unit)
|
|
60
53
|
})
|
|
61
54
|
}
|
|
62
55
|
|
|
63
56
|
export class Acquisition {
|
|
64
|
-
constructor(readonly acquire: Of<void>, readonly release: Of<void>) {}
|
|
57
|
+
constructor(readonly acquire: Fx.Of<void>, readonly release: Fx.Of<void>) {}
|
|
65
58
|
}
|
|
66
59
|
|
|
67
60
|
/**
|
|
@@ -80,7 +73,7 @@ export class Lock extends Semaphore {
|
|
|
80
73
|
export function acquirePermit(semaphore: Semaphore) {
|
|
81
74
|
return pipe(
|
|
82
75
|
semaphore.prepare,
|
|
83
|
-
flatMap(({ acquire, release }) => managed(acquire, constant(release))),
|
|
76
|
+
Fx.flatMap(({ acquire, release }) => managed(acquire, constant(release))),
|
|
84
77
|
)
|
|
85
78
|
}
|
|
86
79
|
|
|
@@ -88,10 +81,10 @@ export function acquirePermit(semaphore: Semaphore) {
|
|
|
88
81
|
* Acquire a permit from a given semaphore, run an Fx, and then release the permit.
|
|
89
82
|
*/
|
|
90
83
|
export function acquire(semaphore: Semaphore) {
|
|
91
|
-
return <R, E, A>(fx: Fx<R, E, A>) =>
|
|
84
|
+
return <R, E, A>(fx: Fx.Fx<R, E, A>) =>
|
|
92
85
|
pipe(
|
|
93
86
|
acquirePermit(semaphore),
|
|
94
|
-
flatMap(() => fx),
|
|
87
|
+
Fx.flatMap(() => fx),
|
|
95
88
|
scoped,
|
|
96
89
|
)
|
|
97
90
|
}
|
|
@@ -100,10 +93,10 @@ export function acquire(semaphore: Semaphore) {
|
|
|
100
93
|
* Acquire a permit from a given semaphore, run an Fx, and then release the permit.
|
|
101
94
|
*/
|
|
102
95
|
export function acquireFiber(semaphore: Semaphore) {
|
|
103
|
-
return <R, E, A>(fx: Fx<R, E, A>) =>
|
|
96
|
+
return <R, E, A>(fx: Fx.Fx<R, E, A>) =>
|
|
104
97
|
pipe(
|
|
105
98
|
acquirePermit(semaphore),
|
|
106
|
-
flatMap(() => fx),
|
|
99
|
+
Fx.flatMap(() => fx),
|
|
107
100
|
fiberScoped,
|
|
108
101
|
)
|
|
109
102
|
}
|
package/src/Sink/Sink.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { flow, pipe } from 'hkt-ts'
|
|
|
2
2
|
import { Left, Right } from 'hkt-ts/Either'
|
|
3
3
|
|
|
4
4
|
import { Cause } from '@/Cause/Cause.js'
|
|
5
|
-
import { Fx, IO, access, flatMap, fromLazy, provide, unit } from '@/Fx/Fx.js'
|
|
5
|
+
import { Fx, IO, access, addCustomTrace, flatMap, fromLazy, provide, unit } from '@/Fx/Fx.js'
|
|
6
6
|
import { Closeable } from '@/Scope/Closeable.js'
|
|
7
7
|
|
|
8
8
|
export interface Sink<in E, in A, out E2 = never> {
|
|
@@ -77,3 +77,13 @@ export function makeDrain<
|
|
|
77
77
|
}),
|
|
78
78
|
)
|
|
79
79
|
}
|
|
80
|
+
|
|
81
|
+
export function addTrace<E, A, E2>(sink: Sink<E, A, E2>, trace?: string): Sink<E, A, E2> {
|
|
82
|
+
if (trace === undefined) return sink
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
event: flow(sink.event, addCustomTrace(trace)),
|
|
86
|
+
error: flow(sink.error, addCustomTrace(trace)),
|
|
87
|
+
end: pipe(sink.end, addCustomTrace(trace)),
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/Stream/Stream.ts
CHANGED
|
@@ -7,14 +7,10 @@ import { Sink } from '@/Sink/Sink.js'
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* TODOS:
|
|
10
|
-
* - Scan
|
|
11
10
|
* - Loop
|
|
12
11
|
* - zipItems
|
|
13
12
|
* - withItems
|
|
14
|
-
* - switchLatest
|
|
15
13
|
* - concatMap
|
|
16
|
-
* - mergeConcurrently
|
|
17
|
-
* - merge/mergeArray
|
|
18
14
|
* - combine/combineArray
|
|
19
15
|
* - zip/zipArray
|
|
20
16
|
* - sample
|
|
@@ -30,24 +26,26 @@ import { Sink } from '@/Sink/Sink.js'
|
|
|
30
26
|
* - delay
|
|
31
27
|
* - throttle
|
|
32
28
|
* - debounce
|
|
33
|
-
* - orElse
|
|
34
|
-
* - multicast
|
|
35
|
-
* - hold
|
|
36
29
|
* - reduce
|
|
37
|
-
* - run
|
|
38
30
|
* - Fusion/Commutation
|
|
39
31
|
* - Unique Identification for streams to add to tracing
|
|
40
32
|
* - How to build a dynamic stream graph?
|
|
41
33
|
*/
|
|
42
34
|
|
|
43
|
-
export interface Stream<R = never, E = never, A = unknown> {
|
|
44
|
-
|
|
35
|
+
export interface Stream<out R = never, out E = never, out A = unknown> {
|
|
36
|
+
fork<E2 = never>(
|
|
45
37
|
sink: Sink<E, A, E2>,
|
|
46
38
|
scheduler: Scheduler,
|
|
47
39
|
context: FiberContext<FiberId.Live>,
|
|
48
|
-
)
|
|
40
|
+
): Fx.RIO<R, Fiber<E2, any>>
|
|
49
41
|
}
|
|
50
42
|
|
|
43
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
44
|
+
export type ResourcesOf<T> = T extends Stream<infer R, infer _, infer __> ? R : never
|
|
45
|
+
export type ErrorsOf<T> = T extends Stream<infer _, infer E, infer __> ? E : never
|
|
46
|
+
export type OutputOf<T> = T extends Stream<infer _, infer __, infer A> ? A : never
|
|
47
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
48
|
+
|
|
51
49
|
export interface RIO<R, A> extends Stream<R, never, A> {}
|
|
52
50
|
export interface IO<E, A> extends Stream<never, E, A> {}
|
|
53
51
|
export interface Of<A> extends Stream<never, never, A> {}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { pipe } from 'hkt-ts/function'
|
|
2
|
+
|
|
3
|
+
import { Stream } from './Stream.js'
|
|
4
|
+
|
|
5
|
+
import { FiberContext } from '@/FiberContext/FiberContext.js'
|
|
6
|
+
import { Live } from '@/FiberId/FiberId.js'
|
|
7
|
+
import * as Fx from '@/Fx/Fx.js'
|
|
8
|
+
import { Scheduler } from '@/Scheduler/index.js'
|
|
9
|
+
import * as Semaphore from '@/Semaphore/index.js'
|
|
10
|
+
import { Sink } from '@/Sink/Sink.js'
|
|
11
|
+
|
|
12
|
+
export function acquirePermit(semaphore: Semaphore.Semaphore) {
|
|
13
|
+
return <R, E, A>(stream: Stream<R, E, A>): Stream<R, E, A> =>
|
|
14
|
+
new AcquirePermitStream(stream, semaphore)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class AcquirePermitStream<R, E, A> implements Stream<R, E, A> {
|
|
18
|
+
constructor(readonly stream: Stream<R, E, A>, readonly semaphore: Semaphore.Semaphore) {}
|
|
19
|
+
|
|
20
|
+
fork = <E2>(sink: Sink<E, A, E2>, scheduler: Scheduler, context: FiberContext<Live>) =>
|
|
21
|
+
pipe(
|
|
22
|
+
this.semaphore.prepare,
|
|
23
|
+
Fx.flatMap(({ acquire, release }) =>
|
|
24
|
+
pipe(
|
|
25
|
+
acquire,
|
|
26
|
+
Fx.uninterruptable,
|
|
27
|
+
Fx.tapLazy(() => context.scope.ensuring(() => release)),
|
|
28
|
+
Fx.flatMap(() => this.stream.fork(sink, scheduler, context)),
|
|
29
|
+
),
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
}
|
package/src/Stream/bimap.ts
CHANGED
|
@@ -12,15 +12,21 @@ import { Sink } from '@/Sink/Sink.js'
|
|
|
12
12
|
export function bimap<A, B, C, D>(
|
|
13
13
|
f: (a: A) => B,
|
|
14
14
|
g: (c: C) => D,
|
|
15
|
+
__trace?: string,
|
|
15
16
|
): <R>(stream: Stream<R, A, C>) => Stream<R, B, D> {
|
|
16
|
-
return (stream) => BimapStream.make(stream, f, g)
|
|
17
|
+
return (stream) => BimapStream.make(stream, f, g, __trace)
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export class BimapStream<R, A, B, C, D> implements Stream<R, B, D> {
|
|
20
|
-
constructor(
|
|
21
|
+
constructor(
|
|
22
|
+
readonly stream: Stream<R, A, C>,
|
|
23
|
+
readonly f: (a: A) => B,
|
|
24
|
+
readonly g: (c: C) => D,
|
|
25
|
+
readonly __trace?: string,
|
|
26
|
+
) {}
|
|
21
27
|
|
|
22
|
-
fork = <
|
|
23
|
-
return this.stream.fork<
|
|
28
|
+
fork = <E>(sink: Sink<B, D, E>, scheduler: Scheduler, context: FiberContext<Live>) => {
|
|
29
|
+
return this.stream.fork<E>(
|
|
24
30
|
new BimapSink(sink, scheduler, context, this.f, this.g),
|
|
25
31
|
scheduler,
|
|
26
32
|
context,
|
|
@@ -31,16 +37,17 @@ export class BimapStream<R, A, B, C, D> implements Stream<R, B, D> {
|
|
|
31
37
|
stream: Stream<R, A, C>,
|
|
32
38
|
f: (a: A) => B,
|
|
33
39
|
g: (c: C) => D,
|
|
40
|
+
__trace?: string,
|
|
34
41
|
): Stream<R, B, D> {
|
|
35
42
|
if (stream instanceof MapStream) {
|
|
36
|
-
return BimapStream.make(stream.stream, f, flow(stream.f, g))
|
|
43
|
+
return BimapStream.make(stream.stream, f, flow(stream.f, g), __trace)
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
if (stream instanceof BimapStream) {
|
|
40
|
-
return BimapStream.make(stream.stream, flow(stream.f, f), flow(stream.g, g))
|
|
47
|
+
return BimapStream.make(stream.stream, flow(stream.f, f), flow(stream.g, g), __trace)
|
|
41
48
|
}
|
|
42
49
|
|
|
43
|
-
return new BimapStream(stream, f, g)
|
|
50
|
+
return new BimapStream(stream, f, g, __trace)
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
|
|
@@ -53,7 +60,7 @@ class BimapSink<A, B, C, D, E> implements Sink<A, C, E> {
|
|
|
53
60
|
readonly g: (c: C) => D,
|
|
54
61
|
) {}
|
|
55
62
|
|
|
56
|
-
event = (
|
|
57
|
-
error = (
|
|
63
|
+
event = flow(this.g, this.sink.event)
|
|
64
|
+
error = flow(Cause.map(this.f), this.sink.error)
|
|
58
65
|
end = this.sink.end
|
|
59
66
|
}
|
|
@@ -8,23 +8,27 @@ import { FiberContext } from '@/FiberContext/FiberContext.js'
|
|
|
8
8
|
import { FiberId } from '@/FiberId/FiberId.js'
|
|
9
9
|
import * as Fx from '@/Fx/index.js'
|
|
10
10
|
import { Scheduler } from '@/Scheduler/Scheduler.js'
|
|
11
|
-
import { Sink } from '@/Sink/Sink.js'
|
|
11
|
+
import { Sink, addTrace } from '@/Sink/Sink.js'
|
|
12
12
|
|
|
13
|
-
export function continueWith<R2, E2, B>(f: () => Stream<R2, E2, B
|
|
13
|
+
export function continueWith<R2, E2, B>(f: () => Stream<R2, E2, B>, __trace?: string) {
|
|
14
14
|
return <R, E, A>(stream: Stream<R, E, A>): Stream<R | R2, E | E2, A | B> =>
|
|
15
|
-
new ContinueWith(stream, f)
|
|
15
|
+
new ContinueWith(stream, f, __trace)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export const startWith =
|
|
19
|
-
<B>(value: B) =>
|
|
19
|
+
<B>(value: B, __trace?: string) =>
|
|
20
20
|
<R, E, A>(stream: Stream<R, E, A>) =>
|
|
21
21
|
pipe(
|
|
22
22
|
now(value),
|
|
23
|
-
continueWith(() => stream),
|
|
23
|
+
continueWith(() => stream, __trace),
|
|
24
24
|
)
|
|
25
25
|
|
|
26
26
|
export class ContinueWith<R, E, A, R2, E2, B> implements Stream<R | R2, E | E2, A | B> {
|
|
27
|
-
constructor(
|
|
27
|
+
constructor(
|
|
28
|
+
readonly stream: Stream<R, E, A>,
|
|
29
|
+
readonly f: () => Stream<R2, E2, B>,
|
|
30
|
+
readonly __trace?: string,
|
|
31
|
+
) {}
|
|
28
32
|
|
|
29
33
|
fork = <E3>(
|
|
30
34
|
sink: Sink<E | E2, A | B, E3>,
|
|
@@ -33,7 +37,7 @@ export class ContinueWith<R, E, A, R2, E2, B> implements Stream<R | R2, E | E2,
|
|
|
33
37
|
) => {
|
|
34
38
|
return Fx.access((env: Env<R | R2>) =>
|
|
35
39
|
this.stream.fork(
|
|
36
|
-
new ContinueWithSink(sink, scheduler, context, env, this.f),
|
|
40
|
+
addTrace(new ContinueWithSink(sink, scheduler, context, env, this.f), this.__trace),
|
|
37
41
|
scheduler,
|
|
38
42
|
context,
|
|
39
43
|
),
|
package/src/Stream/drain.ts
CHANGED
|
@@ -7,18 +7,18 @@ import { FiberContext } from '@/FiberContext/FiberContext.js'
|
|
|
7
7
|
import { FiberId } from '@/FiberId/FiberId.js'
|
|
8
8
|
import * as Fx from '@/Fx/index.js'
|
|
9
9
|
import { Scheduler } from '@/Scheduler/Scheduler.js'
|
|
10
|
-
import { Drain, Sink, makeDrain } from '@/Sink/Sink.js'
|
|
10
|
+
import { Drain, Sink, addTrace, makeDrain } from '@/Sink/Sink.js'
|
|
11
11
|
|
|
12
12
|
export function drain<R, E, A>(
|
|
13
13
|
stream: Stream<R, E, A>,
|
|
14
14
|
__trace?: string,
|
|
15
|
-
): Fx.Fx<R | Scheduler, never, Fiber<
|
|
15
|
+
): Fx.Fx<R | Scheduler, never, Fiber<never, any>> {
|
|
16
16
|
return pipe(
|
|
17
17
|
Fx.Do,
|
|
18
18
|
Fx.bind('fiberContext', () => Fx.getFiberContext),
|
|
19
19
|
Fx.let('context', ({ fiberContext }) => fiberContext.fork()),
|
|
20
20
|
Fx.let('sink', ({ context }) => new Drain<E, A>(context.scope)),
|
|
21
|
-
Fx.flatMap(({ sink, context }) => fork(stream, sink, context), __trace),
|
|
21
|
+
Fx.flatMap(({ sink, context }) => fork(stream, sink, context, __trace), __trace),
|
|
22
22
|
)
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -26,8 +26,9 @@ export function fork<R, E, A, E2 = never>(
|
|
|
26
26
|
stream: Stream<R, E, A>,
|
|
27
27
|
sink: Sink<E, A, E2>,
|
|
28
28
|
context: FiberContext<FiberId.Live>,
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
__trace?: string,
|
|
30
|
+
): Fx.Fx<R | Scheduler, never, Fiber<E2, A>> {
|
|
31
|
+
return Fx.asks(Scheduler)((scheduler) => stream.fork(addTrace(sink, __trace), scheduler, context))
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export function observe<A, R2, E2, B>(f: (a: A) => Fx.Fx<R2, E2, B>, __trace?: string) {
|
|
@@ -37,7 +38,7 @@ export function observe<A, R2, E2, B>(f: (a: A) => Fx.Fx<R2, E2, B>, __trace?: s
|
|
|
37
38
|
Fx.bind('fiberContext', () => Fx.getFiberContext),
|
|
38
39
|
Fx.let('context', ({ fiberContext }) => fiberContext.fork()),
|
|
39
40
|
Fx.bind('sink', ({ context }) => makeDrain<E, A, R2, E2>(context.scope, { event: f })),
|
|
40
|
-
Fx.flatMap(({ sink, context }) => fork(stream, sink, context), __trace),
|
|
41
|
+
Fx.flatMap(({ sink, context }) => fork(stream, sink, context, __trace), __trace),
|
|
41
42
|
)
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -50,7 +51,7 @@ export function collect<R, E, A>(
|
|
|
50
51
|
|
|
51
52
|
yield* pipe(
|
|
52
53
|
stream,
|
|
53
|
-
observe((a) => Fx.fromLazy(() => events.push(a))),
|
|
54
|
+
observe((a) => Fx.fromLazy(() => events.push(a)), __trace),
|
|
54
55
|
Fx.flatMap(Fx.join),
|
|
55
56
|
)
|
|
56
57
|
|
package/src/Stream/empty.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Stream } from './Stream.js'
|
|
2
2
|
|
|
3
3
|
import * as Fx from '@/Fx/Fx.js'
|
|
4
|
-
import { span } from '@/Fx/logging.js'
|
|
5
4
|
|
|
6
5
|
export const empty = Stream<never, never, never>((sink, scheduler, context) =>
|
|
7
|
-
Fx.asksEnv((env) => scheduler.asap(sink.end, env, context
|
|
6
|
+
Fx.asksEnv((env) => scheduler.asap(sink.end, env, context)),
|
|
8
7
|
)
|
|
@@ -2,13 +2,11 @@ import { deepStrictEqual } from 'assert'
|
|
|
2
2
|
|
|
3
3
|
import { pipe } from 'hkt-ts'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { collectAll } from './_internal.test.js'
|
|
6
6
|
import { flatMap } from './flatMap.js'
|
|
7
7
|
import { fromFx } from './fromFx.js'
|
|
8
8
|
|
|
9
9
|
import * as Fx from '@/Fx/index.js'
|
|
10
|
-
import { RootScheduler } from '@/Scheduler/RootScheduler.js'
|
|
11
|
-
import { Scheduler } from '@/Scheduler/Scheduler.js'
|
|
12
10
|
import { testSuite } from '@/_internal/suite.js'
|
|
13
11
|
|
|
14
12
|
testSuite(import.meta.url, () => {
|
|
@@ -19,25 +17,14 @@ testSuite(import.meta.url, () => {
|
|
|
19
17
|
flatMap((a) => fromFx(Fx.success(a + 1))),
|
|
20
18
|
)
|
|
21
19
|
|
|
22
|
-
it('
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Fx.flatMap(Fx.join),
|
|
27
|
-
Fx.provideService(Scheduler, RootScheduler()),
|
|
28
|
-
Fx.runMain,
|
|
29
|
-
))
|
|
30
|
-
|
|
31
|
-
it('should be collectable', async () => {
|
|
32
|
-
await pipe(
|
|
33
|
-
Fx.Fx(function* () {
|
|
34
|
-
const events: readonly number[] = yield* collect(stream)
|
|
20
|
+
it('is collectable', async () => {
|
|
21
|
+
const events = await collectAll(stream)
|
|
22
|
+
deepStrictEqual(events, [value + 1])
|
|
23
|
+
})
|
|
35
24
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Fx.runMain,
|
|
40
|
-
)
|
|
25
|
+
it('is collectable with multiple subscribers', async () => {
|
|
26
|
+
const events = await Promise.all([collectAll(stream), collectAll(stream)])
|
|
27
|
+
deepStrictEqual(events, [[value + 1], [value + 1]])
|
|
41
28
|
})
|
|
42
29
|
})
|
|
43
30
|
})
|