@fncts/io 0.0.41 → 0.0.43
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/Fiber/FiberRuntime.d.ts +2 -2
- package/Fiber/definition.d.ts +1 -0
- package/FiberSet.d.ts +66 -0
- package/Hub/definition.d.ts +3 -0
- package/Hub/internal.d.ts +1 -0
- package/IO/api/diffFiberRefs.d.ts +7 -0
- package/IO/api/timeout.d.ts +5 -0
- package/IO/api.d.ts +12 -1
- package/IO/definition.d.ts +18 -7
- package/IO.d.ts +1 -0
- package/Layer/api.d.ts +5 -0
- package/Queue/api/dimapIO.d.ts +5 -0
- package/Queue/api/filterInputIO.d.ts +1 -1
- package/Queue/api/filterOutputIO.d.ts +1 -0
- package/Queue/api/operations.d.ts +11 -0
- package/Queue/api/zipWithIO.d.ts +1 -0
- package/Queue/definition.d.ts +5 -0
- package/Queue/internal.d.ts +1 -0
- package/STM/definition.d.ts +1 -1
- package/Stream/api.d.ts +10 -0
- package/_cjs/Channel/api/mapOutConcurrentIO.cjs +2 -8
- package/_cjs/Channel/api/mapOutConcurrentIO.cjs.map +1 -1
- package/_cjs/Channel/api/mergeAllWith.cjs +14 -23
- package/_cjs/Channel/api/mergeAllWith.cjs.map +1 -1
- package/_cjs/Channel/api/mergeWith.cjs +4 -16
- package/_cjs/Channel/api/mergeWith.cjs.map +1 -1
- package/_cjs/Channel/api.cjs +18 -33
- package/_cjs/Channel/api.cjs.map +1 -1
- package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs +2 -8
- package/_cjs/Channel/internal/SingleProducerAsyncInput.cjs.map +1 -1
- package/_cjs/Fiber/FiberRuntime.cjs +86 -75
- package/_cjs/Fiber/FiberRuntime.cjs.map +1 -1
- package/_cjs/Fiber/definition.cjs.map +1 -1
- package/_cjs/FiberSet.cjs +129 -0
- package/_cjs/FiberSet.cjs.map +1 -0
- package/_cjs/Hub/api.cjs +20 -11
- package/_cjs/Hub/api.cjs.map +1 -1
- package/_cjs/Hub/definition.cjs +3 -0
- package/_cjs/Hub/definition.cjs.map +1 -1
- package/_cjs/Hub/internal.cjs +65 -49
- package/_cjs/Hub/internal.cjs.map +1 -1
- package/_cjs/IO/api/asyncInterrupt.cjs +4 -7
- package/_cjs/IO/api/asyncInterrupt.cjs.map +1 -1
- package/_cjs/IO/api/diffFiberRefs.cjs +17 -0
- package/_cjs/IO/api/diffFiberRefs.cjs.map +1 -0
- package/_cjs/IO/api/memoize.cjs +7 -4
- package/_cjs/IO/api/memoize.cjs.map +1 -1
- package/_cjs/IO/api/timeout.cjs +8 -0
- package/_cjs/IO/api/timeout.cjs.map +1 -1
- package/_cjs/IO/api.cjs +33 -42
- package/_cjs/IO/api.cjs.map +1 -1
- package/_cjs/IO/definition.cjs +9 -3
- package/_cjs/IO/definition.cjs.map +1 -1
- package/_cjs/IO/runtime.cjs +3 -6
- package/_cjs/IO/runtime.cjs.map +1 -1
- package/_cjs/IO.cjs +11 -0
- package/_cjs/IO.cjs.map +1 -1
- package/_cjs/Layer/api.cjs +9 -5
- package/_cjs/Layer/api.cjs.map +1 -1
- package/_cjs/Push/api.cjs +1 -4
- package/_cjs/Push/api.cjs.map +1 -1
- package/_cjs/Queue/api/dimapIO.cjs +28 -10
- package/_cjs/Queue/api/dimapIO.cjs.map +1 -1
- package/_cjs/Queue/api/filterInputIO.cjs +21 -9
- package/_cjs/Queue/api/filterInputIO.cjs.map +1 -1
- package/_cjs/Queue/api/filterOutputIO.cjs +28 -16
- package/_cjs/Queue/api/filterOutputIO.cjs.map +1 -1
- package/_cjs/Queue/api/operations.cjs +20 -0
- package/_cjs/Queue/api/operations.cjs.map +1 -1
- package/_cjs/Queue/api/zipWithIO.cjs +16 -9
- package/_cjs/Queue/api/zipWithIO.cjs.map +1 -1
- package/_cjs/Queue/definition.cjs.map +1 -1
- package/_cjs/Queue/internal.cjs +84 -54
- package/_cjs/Queue/internal.cjs.map +1 -1
- package/_cjs/Ref/Derived.cjs +8 -35
- package/_cjs/Ref/Derived.cjs.map +1 -1
- package/_cjs/Ref/DerivedAll.cjs +8 -35
- package/_cjs/Ref/DerivedAll.cjs.map +1 -1
- package/_cjs/STM/api/core-api.cjs +1 -4
- package/_cjs/STM/api/core-api.cjs.map +1 -1
- package/_cjs/STM/api.cjs +4 -16
- package/_cjs/STM/api.cjs.map +1 -1
- package/_cjs/STM/definition.cjs +1 -1
- package/_cjs/STM/definition.cjs.map +1 -1
- package/_cjs/Schedule/api.cjs +1 -7
- package/_cjs/Schedule/api.cjs.map +1 -1
- package/_cjs/Sink/api.cjs +1 -7
- package/_cjs/Sink/api.cjs.map +1 -1
- package/_cjs/Stream/api/zipAllWith.cjs +1 -4
- package/_cjs/Stream/api/zipAllWith.cjs.map +1 -1
- package/_cjs/Stream/api/zipWithChunks.cjs +1 -4
- package/_cjs/Stream/api/zipWithChunks.cjs.map +1 -1
- package/_cjs/Stream/api.cjs +51 -37
- package/_cjs/Stream/api.cjs.map +1 -1
- package/_cjs/TRef/definition.cjs +20 -74
- package/_cjs/TRef/definition.cjs.map +1 -1
- package/_cjs/internal/BackgroundScheduler.cjs +0 -1
- package/_cjs/internal/BackgroundScheduler.cjs.map +1 -1
- package/_mjs/Channel/api/mapOutConcurrentIO.mjs +2 -8
- package/_mjs/Channel/api/mapOutConcurrentIO.mjs.map +1 -1
- package/_mjs/Channel/api/mergeAllWith.mjs +14 -23
- package/_mjs/Channel/api/mergeAllWith.mjs.map +1 -1
- package/_mjs/Channel/api/mergeWith.mjs +4 -16
- package/_mjs/Channel/api/mergeWith.mjs.map +1 -1
- package/_mjs/Channel/api.mjs +18 -33
- package/_mjs/Channel/api.mjs.map +1 -1
- package/_mjs/Channel/internal/SingleProducerAsyncInput.mjs +2 -8
- package/_mjs/Channel/internal/SingleProducerAsyncInput.mjs.map +1 -1
- package/_mjs/Fiber/FiberRuntime.mjs +86 -75
- package/_mjs/Fiber/FiberRuntime.mjs.map +1 -1
- package/_mjs/Fiber/definition.mjs.map +1 -1
- package/_mjs/FiberSet.mjs +113 -0
- package/_mjs/FiberSet.mjs.map +1 -0
- package/_mjs/Hub/api.mjs +20 -11
- package/_mjs/Hub/api.mjs.map +1 -1
- package/_mjs/Hub/definition.mjs +3 -0
- package/_mjs/Hub/definition.mjs.map +1 -1
- package/_mjs/Hub/internal.mjs +65 -49
- package/_mjs/Hub/internal.mjs.map +1 -1
- package/_mjs/IO/api/asyncInterrupt.mjs +4 -7
- package/_mjs/IO/api/asyncInterrupt.mjs.map +1 -1
- package/_mjs/IO/api/diffFiberRefs.mjs +9 -0
- package/_mjs/IO/api/diffFiberRefs.mjs.map +1 -0
- package/_mjs/IO/api/memoize.mjs +7 -4
- package/_mjs/IO/api/memoize.mjs.map +1 -1
- package/_mjs/IO/api/timeout.mjs +7 -0
- package/_mjs/IO/api/timeout.mjs.map +1 -1
- package/_mjs/IO/api.mjs +30 -40
- package/_mjs/IO/api.mjs.map +1 -1
- package/_mjs/IO/definition.mjs +7 -2
- package/_mjs/IO/definition.mjs.map +1 -1
- package/_mjs/IO/runtime.mjs +3 -6
- package/_mjs/IO/runtime.mjs.map +1 -1
- package/_mjs/IO.mjs +1 -0
- package/_mjs/IO.mjs.map +1 -1
- package/_mjs/Layer/api.mjs +8 -5
- package/_mjs/Layer/api.mjs.map +1 -1
- package/_mjs/Push/api.mjs +1 -4
- package/_mjs/Push/api.mjs.map +1 -1
- package/_mjs/Queue/api/dimapIO.mjs +28 -10
- package/_mjs/Queue/api/dimapIO.mjs.map +1 -1
- package/_mjs/Queue/api/filterInputIO.mjs +21 -9
- package/_mjs/Queue/api/filterInputIO.mjs.map +1 -1
- package/_mjs/Queue/api/filterOutputIO.mjs +28 -16
- package/_mjs/Queue/api/filterOutputIO.mjs.map +1 -1
- package/_mjs/Queue/api/operations.mjs +18 -0
- package/_mjs/Queue/api/operations.mjs.map +1 -1
- package/_mjs/Queue/api/zipWithIO.mjs +16 -9
- package/_mjs/Queue/api/zipWithIO.mjs.map +1 -1
- package/_mjs/Queue/definition.mjs.map +1 -1
- package/_mjs/Queue/internal.mjs +84 -54
- package/_mjs/Queue/internal.mjs.map +1 -1
- package/_mjs/Ref/Derived.mjs +8 -35
- package/_mjs/Ref/Derived.mjs.map +1 -1
- package/_mjs/Ref/DerivedAll.mjs +8 -35
- package/_mjs/Ref/DerivedAll.mjs.map +1 -1
- package/_mjs/STM/api/core-api.mjs +1 -4
- package/_mjs/STM/api/core-api.mjs.map +1 -1
- package/_mjs/STM/api.mjs +4 -16
- package/_mjs/STM/api.mjs.map +1 -1
- package/_mjs/STM/definition.mjs +1 -1
- package/_mjs/STM/definition.mjs.map +1 -1
- package/_mjs/Schedule/api.mjs +1 -7
- package/_mjs/Schedule/api.mjs.map +1 -1
- package/_mjs/Sink/api.mjs +1 -7
- package/_mjs/Sink/api.mjs.map +1 -1
- package/_mjs/Stream/api/zipAllWith.mjs +1 -4
- package/_mjs/Stream/api/zipAllWith.mjs.map +1 -1
- package/_mjs/Stream/api/zipWithChunks.mjs +1 -4
- package/_mjs/Stream/api/zipWithChunks.mjs.map +1 -1
- package/_mjs/Stream/api.mjs +47 -36
- package/_mjs/Stream/api.mjs.map +1 -1
- package/_mjs/TRef/definition.mjs +20 -74
- package/_mjs/TRef/definition.mjs.map +1 -1
- package/_mjs/internal/BackgroundScheduler.mjs +0 -1
- package/_mjs/internal/BackgroundScheduler.mjs.map +1 -1
- package/_src/Channel/api/mapOutConcurrentIO.ts +5 -5
- package/_src/Channel/api/mergeAllWith.ts +9 -9
- package/_src/Channel/api/mergeWith.ts +16 -16
- package/_src/Channel/api.ts +12 -32
- package/_src/Channel/internal/SingleProducerAsyncInput.ts +2 -2
- package/_src/Fiber/FiberRuntime.ts +50 -36
- package/_src/Fiber/definition.ts +2 -0
- package/_src/FiberSet.ts +115 -0
- package/_src/Hub/api.ts +15 -6
- package/_src/Hub/definition.ts +6 -0
- package/_src/Hub/internal.ts +19 -0
- package/_src/IO/api/asyncInterrupt.ts +4 -4
- package/_src/IO/api/diffFiberRefs.ts +11 -0
- package/_src/IO/api/memoize.ts +5 -3
- package/_src/IO/api/timeout.ts +8 -0
- package/_src/IO/api.ts +32 -19
- package/_src/IO/definition.ts +20 -4
- package/_src/IO/runtime.ts +3 -6
- package/_src/IO.ts +1 -0
- package/_src/Layer/api.ts +11 -4
- package/_src/Push/api.ts +4 -4
- package/_src/Queue/api/dimapIO.ts +25 -0
- package/_src/Queue/api/filterInputIO.ts +16 -0
- package/_src/Queue/api/filterOutputIO.ts +16 -0
- package/_src/Queue/api/operations.ts +20 -0
- package/_src/Queue/api/zipWithIO.ts +8 -0
- package/_src/Queue/definition.ts +4 -0
- package/_src/Queue/internal.ts +32 -0
- package/_src/Ref/Derived.ts +18 -20
- package/_src/Ref/DerivedAll.ts +18 -21
- package/_src/STM/api/core-api.ts +1 -1
- package/_src/STM/api.ts +4 -4
- package/_src/STM/definition.ts +1 -1
- package/_src/Schedule/api.ts +8 -8
- package/_src/Sink/api.ts +8 -8
- package/_src/Stream/api/zipAllWith.ts +4 -4
- package/_src/Stream/api/zipWithChunks.ts +4 -4
- package/_src/Stream/api.ts +75 -22
- package/_src/TRef/definition.ts +33 -36
- package/_src/global.ts +4 -0
- package/_src/index.ts +1 -0
- package/_src/internal/BackgroundScheduler.ts +0 -1
- package/global.d.ts +4 -0
- package/index.d.ts +1 -0
- package/package.json +4 -4
@@ -3,8 +3,10 @@ import type { OnFailure, OnSuccess, OnSuccessAndFailure, UIO } from "../IO/defin
|
|
3
3
|
import type { WhileLoop } from "../IO/definition.js";
|
4
4
|
import type { RuntimeFlags } from "../RuntimeFlags.js";
|
5
5
|
|
6
|
+
import { EitherTag } from "@fncts/base/data/Either";
|
6
7
|
import { isIOError } from "@fncts/base/data/exceptions";
|
7
8
|
import { ExitTag } from "@fncts/base/data/Exit";
|
9
|
+
import { MaybeTag } from "@fncts/base/data/Maybe";
|
8
10
|
import { Trace } from "@fncts/base/data/Trace";
|
9
11
|
import { FiberTypeId, FiberVariance } from "@fncts/io/Fiber/definition";
|
10
12
|
import { StackTraceBuilder } from "@fncts/io/internal/StackTraceBuilder";
|
@@ -19,7 +21,7 @@ import { RuntimeFlag } from "../RuntimeFlag.js";
|
|
19
21
|
import { FiberMessage, FiberMessageTag } from "./FiberMessage.js";
|
20
22
|
|
21
23
|
export class RevertFlags {
|
22
|
-
readonly
|
24
|
+
readonly _ioOpCode = IOTag.RevertFlags;
|
23
25
|
constructor(
|
24
26
|
readonly patch: RuntimeFlags.Patch,
|
25
27
|
readonly trace?: string,
|
@@ -27,7 +29,7 @@ export class RevertFlags {
|
|
27
29
|
}
|
28
30
|
|
29
31
|
export class UpdateTrace {
|
30
|
-
readonly
|
32
|
+
readonly _ioOpCode = IOTag.UpdateTrace;
|
31
33
|
constructor(readonly trace?: string) {}
|
32
34
|
}
|
33
35
|
|
@@ -269,7 +271,7 @@ export class FiberRuntime<E, A> implements Fiber.Runtime<E, A> {
|
|
269
271
|
}
|
270
272
|
} catch (e) {
|
271
273
|
if (isIO(e)) {
|
272
|
-
if (IO.concrete(e).
|
274
|
+
if (IO.concrete(e)._ioOpCode === IOTag.YieldNow) {
|
273
275
|
if (this._runtimeFlags.cooperativeYielding) {
|
274
276
|
this.tell(FiberMessage.YieldNow);
|
275
277
|
this.tell(FiberMessage.Resume(IO.unit));
|
@@ -277,10 +279,10 @@ export class FiberRuntime<E, A> implements Fiber.Runtime<E, A> {
|
|
277
279
|
} else {
|
278
280
|
effect = IO.unit;
|
279
281
|
}
|
280
|
-
} else if (IO.concrete(e).
|
282
|
+
} else if (IO.concrete(e)._ioOpCode === IOTag.Async) {
|
281
283
|
effect = null!;
|
282
284
|
} else {
|
283
|
-
throw new Error(`Unhandled op ${IO.concrete(e).
|
285
|
+
throw new Error(`Unhandled op ${IO.concrete(e)._ioOpCode}`);
|
284
286
|
}
|
285
287
|
} else {
|
286
288
|
throw e;
|
@@ -318,12 +320,12 @@ export class FiberRuntime<E, A> implements Fiber.Runtime<E, A> {
|
|
318
320
|
cur = IO.concrete(IO.yieldNow.flatMap(() => oldCur, trace));
|
319
321
|
}
|
320
322
|
try {
|
321
|
-
switch (cur.
|
323
|
+
switch (cur._ioOpCode) {
|
322
324
|
case IOTag.Sync: {
|
323
325
|
const value = cur.i0();
|
324
326
|
const cont = this.getNextSuccessCont();
|
325
327
|
if (cont) {
|
326
|
-
switch (cont.
|
328
|
+
switch (cont._ioOpCode) {
|
327
329
|
case IOTag.OnSuccess: {
|
328
330
|
cur = IO.concrete(cont.i1(value));
|
329
331
|
break;
|
@@ -406,7 +408,7 @@ export class FiberRuntime<E, A> implements Fiber.Runtime<E, A> {
|
|
406
408
|
const oldCur = cur;
|
407
409
|
const cont = this.getNextSuccessCont();
|
408
410
|
if (cont) {
|
409
|
-
switch (cont.
|
411
|
+
switch (cont._ioOpCode) {
|
410
412
|
case IOTag.OnSuccess: {
|
411
413
|
cur = IO.concrete(cont.i1(oldCur.i0));
|
412
414
|
break;
|
@@ -447,7 +449,7 @@ export class FiberRuntime<E, A> implements Fiber.Runtime<E, A> {
|
|
447
449
|
const cause = cur.i0();
|
448
450
|
const cont = this.getNextFailCont();
|
449
451
|
if (cont) {
|
450
|
-
switch (cont.
|
452
|
+
switch (cont._ioOpCode) {
|
451
453
|
case IOTag.OnFailure:
|
452
454
|
case IOTag.OnSuccessAndFailure: {
|
453
455
|
if (!(this._runtimeFlags.interruptible && this.isInterrupted())) {
|
@@ -504,38 +506,50 @@ export class FiberRuntime<E, A> implements Fiber.Runtime<E, A> {
|
|
504
506
|
cur = IO.concrete(cur.commit);
|
505
507
|
break;
|
506
508
|
}
|
507
|
-
case
|
508
|
-
cur = IO.concrete(
|
509
|
+
case IOTag.External: {
|
510
|
+
cur = IO.concrete(cur.toIO);
|
509
511
|
break;
|
510
512
|
}
|
511
|
-
case
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
513
|
+
case null: {
|
514
|
+
switch (cur._tag) {
|
515
|
+
case MaybeTag.Just: {
|
516
|
+
cur = IO.concrete(IO.succeedNow(cur.value));
|
517
|
+
break;
|
518
|
+
}
|
519
|
+
case MaybeTag.Nothing: {
|
520
|
+
cur = IO.concrete(IO.failNow(new NoSuchElementError()));
|
521
|
+
break;
|
522
|
+
}
|
523
|
+
case EitherTag.Left: {
|
524
|
+
cur = IO.concrete(IO.failNow(cur.left));
|
525
|
+
break;
|
526
|
+
}
|
527
|
+
case EitherTag.Right: {
|
528
|
+
cur = IO.concrete(IO.succeedNow(cur.right));
|
529
|
+
break;
|
530
|
+
}
|
531
|
+
case ExitTag.Failure: {
|
532
|
+
cur = IO.concrete(IO.failCauseNow(cur.cause));
|
533
|
+
break;
|
534
|
+
}
|
535
|
+
case ExitTag.Success: {
|
536
|
+
cur = IO.concrete(IO.succeedNow(cur.value));
|
537
|
+
break;
|
538
|
+
}
|
539
|
+
case "Tag": {
|
540
|
+
cur = IO.concrete(IO.service(cur));
|
541
|
+
break;
|
542
|
+
}
|
543
|
+
}
|
533
544
|
}
|
534
545
|
}
|
535
546
|
} catch (e) {
|
536
547
|
if (isIOError(e)) {
|
537
548
|
cur = IO.concrete(IO.failCauseNow(e.cause));
|
538
|
-
} else if (
|
549
|
+
} else if (
|
550
|
+
isIO(e) &&
|
551
|
+
(IO.concrete(e)._ioOpCode === IOTag.Async || IO.concrete(e)._ioOpCode === IOTag.YieldNow)
|
552
|
+
) {
|
539
553
|
throw e;
|
540
554
|
} else if (isInterruptedException(e)) {
|
541
555
|
cur = IO.concrete(IO.failCauseNow(Cause.parallel(Cause.halt(e), Cause.interrupt(FiberId.none))));
|
@@ -836,7 +850,7 @@ export class FiberRuntime<E, A> implements Fiber.Runtime<E, A> {
|
|
836
850
|
getNextSuccessCont() {
|
837
851
|
while (this.stack.hasNext) {
|
838
852
|
const frame = this.stack.pop()!;
|
839
|
-
if (frame.
|
853
|
+
if (frame._ioOpCode !== IOTag.OnFailure) {
|
840
854
|
return frame;
|
841
855
|
}
|
842
856
|
}
|
@@ -845,7 +859,7 @@ export class FiberRuntime<E, A> implements Fiber.Runtime<E, A> {
|
|
845
859
|
getNextFailCont() {
|
846
860
|
while (this.stack.hasNext) {
|
847
861
|
const frame = this.stack.pop()!;
|
848
|
-
if (frame.
|
862
|
+
if (frame._ioOpCode !== IOTag.OnSuccess && frame._ioOpCode !== IOTag.WhileLoop) {
|
849
863
|
return frame;
|
850
864
|
}
|
851
865
|
}
|
package/_src/Fiber/definition.ts
CHANGED
@@ -89,6 +89,8 @@ export interface RuntimeFiber<E, A> extends FiberCommon<E, A> {
|
|
89
89
|
* The trace of the Fiber
|
90
90
|
*/
|
91
91
|
readonly trace: UIO<Trace>;
|
92
|
+
|
93
|
+
addObserver(observer: (exit: Exit<E, A>) => void): void;
|
92
94
|
}
|
93
95
|
|
94
96
|
export class SyntheticFiber<E, A> implements FiberCommon<E, A> {
|
package/_src/FiberSet.ts
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
export const FiberSetTypeId = Symbol.for("fncts.io.FiberSet");
|
2
|
+
export type FiberSetTypeId = typeof FiberSetTypeId;
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @tsplus type fncts.io.FiberSet
|
6
|
+
* @tsplus companion fncts.io.FiberSetOps
|
7
|
+
*/
|
8
|
+
export class FiberSet<E, A> {
|
9
|
+
readonly [FiberSetTypeId]: FiberSetTypeId = FiberSetTypeId;
|
10
|
+
constructor(
|
11
|
+
readonly backing: Set<Fiber.Runtime<E, A>>,
|
12
|
+
readonly future: Future<unknown, never>,
|
13
|
+
) {}
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @tsplus static fncts.io.FiberSetOps unsafeMake
|
18
|
+
*/
|
19
|
+
export function unsafeMake<E, A>(backing: Set<Fiber.Runtime<E, A>>, future: Future<unknown, never>): FiberSet<E, A> {
|
20
|
+
return new FiberSet(backing, future);
|
21
|
+
}
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @tsplus static fncts.io.FiberSetOps make
|
25
|
+
*/
|
26
|
+
export function make<E, A>(): IO<Scope, never, FiberSet<E, A>> {
|
27
|
+
return IO.acquireRelease(
|
28
|
+
Future.make<unknown, never>().map((future) => FiberSet.unsafeMake(new Set<Fiber.Runtime<E, A>>(), future)),
|
29
|
+
(fiberSet) => fiberSet.clear,
|
30
|
+
);
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* @tsplus static fncts.io.FiberSetOps makeRuntime
|
35
|
+
*/
|
36
|
+
export function makeRuntime<R, E, A>(): IO<
|
37
|
+
Scope | R,
|
38
|
+
never,
|
39
|
+
<XE extends E, XA extends A>(io: IO<R, XE, XA>) => Fiber.Runtime<XE, XA>
|
40
|
+
> {
|
41
|
+
return make<E, A>().flatMap((fiberSet) => fiberSet.runtime());
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @tsplus pipeable fncts.io.FiberSet unsafeAdd
|
46
|
+
*/
|
47
|
+
export function unsafeAdd<XE extends E, XA extends A, E, A>(fiber: Fiber.Runtime<XE, XA>) {
|
48
|
+
return (self: FiberSet<E, A>): void => {
|
49
|
+
if (self.backing.has(fiber)) {
|
50
|
+
return;
|
51
|
+
}
|
52
|
+
self.backing.add(fiber);
|
53
|
+
fiber.addObserver((exit) => {
|
54
|
+
self.backing.delete(fiber);
|
55
|
+
if (exit.isFailure() && !exit.cause.isInterruptedOnly) {
|
56
|
+
self.future.unsafeDone(exit);
|
57
|
+
}
|
58
|
+
});
|
59
|
+
};
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @tsplus pipeable fncts.io.FiberSet add
|
64
|
+
*/
|
65
|
+
export function add<XE extends E, XA extends A, E, A>(fiber: Fiber.Runtime<XE, XA>) {
|
66
|
+
return (self: FiberSet<E, A>): UIO<void> => IO(self.unsafeAdd(fiber));
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @tsplus pipeable fncts.io.FiberSet runtime
|
71
|
+
*/
|
72
|
+
export function runtime<R = never>() {
|
73
|
+
return <E, A>(
|
74
|
+
self: FiberSet<E, A>,
|
75
|
+
): IO<R, never, <XE extends E, XA extends A>(io: IO<R, XE, XA>) => Fiber.Runtime<XE, XA>> => {
|
76
|
+
return IO.runtime<R>().map((runtime) => {
|
77
|
+
const runFork = runtime.unsafeRunFiber;
|
78
|
+
return (io) => {
|
79
|
+
const fiber = runFork(io);
|
80
|
+
self.unsafeAdd(fiber);
|
81
|
+
return fiber;
|
82
|
+
};
|
83
|
+
});
|
84
|
+
};
|
85
|
+
}
|
86
|
+
|
87
|
+
/**
|
88
|
+
* @tsplus pipeable fncts.io.FiberSet run
|
89
|
+
*/
|
90
|
+
export function run<R, XE extends E, XA extends A, E, A>(io: IO<R, XE, XA>) {
|
91
|
+
return (self: FiberSet<E, A>): IO<R, never, Fiber.Runtime<XE, XA>> => {
|
92
|
+
return io.forkDaemon.tap((fiber) => self.add(fiber));
|
93
|
+
};
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* @tsplus getter fncts.io.FiberSet size
|
98
|
+
*/
|
99
|
+
export function size<E, A>(self: FiberSet<E, A>): UIO<number> {
|
100
|
+
return IO(self.backing.size);
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* @tsplus getter fncts.io.FiberSet join
|
105
|
+
*/
|
106
|
+
export function join<E, A>(self: FiberSet<E, A>): FIO<E, never> {
|
107
|
+
return (self.future as Future<E, never>).await;
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* @tsplus getter fncts.io.FiberSet clear
|
112
|
+
*/
|
113
|
+
export function clear<E, A>(self: FiberSet<E, A>): UIO<void> {
|
114
|
+
return IO.foreach(self.backing, (fiber) => fiber.interrupt) > IO(self.backing.clear());
|
115
|
+
}
|
package/_src/Hub/api.ts
CHANGED
@@ -68,6 +68,9 @@ class DimapIO<RA, RB, RC, RD, EA, EB, EC, ED, A, B, C, D> extends PHubInternal<
|
|
68
68
|
isShutdown = this.source.isShutdown;
|
69
69
|
shutdown = this.source.shutdown;
|
70
70
|
size = this.source.size;
|
71
|
+
get unsafeSize() {
|
72
|
+
return this.source.unsafeSize;
|
73
|
+
}
|
71
74
|
subscribe: IO<Scope, never, PDequeue<RA | RC, RB | RD, EA | EC, EB | ED, C, D>> = unsafeCoerce(
|
72
75
|
this.source.subscribe.map((queue) => queue.mapIO(this.g)),
|
73
76
|
);
|
@@ -119,9 +122,12 @@ class FilterInputIO<RA, RA1, RB, EA, EA1, EB, A, B> extends PHubInternal<RA | RA
|
|
119
122
|
isShutdown = this.source.isShutdown;
|
120
123
|
shutdown = this.source.shutdown;
|
121
124
|
size = this.source.size;
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
+
get unsafeSize() {
|
126
|
+
return this.source.unsafeSize;
|
127
|
+
}
|
128
|
+
subscribe = this.source.subscribe;
|
129
|
+
publish = (a: A) => this.f(a).flatMap((b) => (b ? this.source.publish(a) : IO.succeedNow(false)));
|
130
|
+
publishAll = (as: Iterable<A>) =>
|
125
131
|
IO.filter(as, this.f).flatMap((as) => (as.isNonEmpty ? this.source.publishAll(as) : IO.succeedNow(false)));
|
126
132
|
}
|
127
133
|
|
@@ -161,9 +167,12 @@ class FilterOutputIO<RA, RB, RB1, EA, EB, EB1, A, B> extends PHubInternal<RA, RB
|
|
161
167
|
isShutdown = this.source.isShutdown;
|
162
168
|
shutdown = this.source.shutdown;
|
163
169
|
size = this.source.size;
|
164
|
-
|
165
|
-
|
166
|
-
|
170
|
+
get unsafeSize() {
|
171
|
+
return this.source.unsafeSize;
|
172
|
+
}
|
173
|
+
subscribe = this.source.subscribe.map((queue) => queue.filterOutputIO(this.f));
|
174
|
+
publish = (a: A) => this.source.publish(a);
|
175
|
+
publishAll = (as: Iterable<A>) => this.source.publishAll(as);
|
167
176
|
}
|
168
177
|
|
169
178
|
/**
|
package/_src/Hub/definition.ts
CHANGED
@@ -84,6 +84,8 @@ export abstract class PHubInternal<RA, RB, EA, EB, A, B>
|
|
84
84
|
*/
|
85
85
|
abstract isShutdown: UIO<boolean>;
|
86
86
|
|
87
|
+
abstract unsafeSize: Maybe<number>;
|
88
|
+
|
87
89
|
/**
|
88
90
|
* Publishes a message to the hub, returning whether the message was
|
89
91
|
* published to the hub.
|
@@ -113,6 +115,10 @@ export abstract class PHubInternal<RA, RB, EA, EB, A, B>
|
|
113
115
|
*/
|
114
116
|
abstract subscribe: IO<Scope, never, PDequeue<RA, RB, EA, EB, A, B>>;
|
115
117
|
|
118
|
+
unsafeOffer(_: never): boolean {
|
119
|
+
throw new Error("Cannot unsafely publish to a Hub");
|
120
|
+
}
|
121
|
+
|
116
122
|
offer(a: A, __tsplusTrace?: string): IO<RA, EA, boolean> {
|
117
123
|
return this.publish(a);
|
118
124
|
}
|
package/_src/Hub/internal.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { Maybe } from "@fncts/base/data/Maybe";
|
1
2
|
import type { Hub as HubInternal } from "@fncts/io/internal/Hub";
|
2
3
|
|
3
4
|
import { HashSet } from "@fncts/base/collection/mutable/HashSet";
|
@@ -282,6 +283,13 @@ class UnsafeSubscription<A> extends QueueInternal<never, never, never, never, A,
|
|
282
283
|
}),
|
283
284
|
);
|
284
285
|
|
286
|
+
get unsafeSize(): Maybe<number> {
|
287
|
+
if (this.shutdownFlag.get) {
|
288
|
+
return Nothing();
|
289
|
+
}
|
290
|
+
return Just(this.subscription.size());
|
291
|
+
}
|
292
|
+
|
285
293
|
size: UIO<number> = IO.defer(() => {
|
286
294
|
if (this.shutdownFlag.get) {
|
287
295
|
return IO.interrupt;
|
@@ -290,6 +298,10 @@ class UnsafeSubscription<A> extends QueueInternal<never, never, never, never, A,
|
|
290
298
|
return IO.succeed(this.subscription.size());
|
291
299
|
});
|
292
300
|
|
301
|
+
unsafeOffer(_: never): boolean {
|
302
|
+
return false;
|
303
|
+
}
|
304
|
+
|
293
305
|
offer = (_: never): IO<never, never, boolean> => IO.succeedNow(false);
|
294
306
|
|
295
307
|
offerAll = (_: Iterable<never>): IO<never, never, boolean> => IO.succeedNow(false);
|
@@ -423,6 +435,13 @@ class UnsafeHub<A> extends PHubInternal<never, never, never, never, A, A> {
|
|
423
435
|
}),
|
424
436
|
).uninterruptible;
|
425
437
|
|
438
|
+
get unsafeSize(): Maybe<number> {
|
439
|
+
if (this.shutdownFlag.get) {
|
440
|
+
return Nothing();
|
441
|
+
}
|
442
|
+
return Just(this.hub.size());
|
443
|
+
}
|
444
|
+
|
426
445
|
size = IO.defer(() => {
|
427
446
|
if (this.shutdownFlag.get) {
|
428
447
|
return IO.interrupt;
|
@@ -25,14 +25,14 @@ export function asyncInterrupt<R, E, A>(
|
|
25
25
|
let cancelerRef: URIO<R, any> = IO.unit!;
|
26
26
|
return IO.async<R, E, A>((k) => {
|
27
27
|
const result = register(k);
|
28
|
-
result.match(
|
29
|
-
|
28
|
+
result.match(
|
29
|
+
(canceler) => {
|
30
30
|
cancelerRef = canceler;
|
31
31
|
},
|
32
|
-
|
32
|
+
(done) => {
|
33
33
|
k(done);
|
34
34
|
},
|
35
|
-
|
35
|
+
);
|
36
36
|
}, blockingOn).onInterrupt(() => cancelerRef);
|
37
37
|
});
|
38
38
|
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { FiberRefsPatch } from "@fncts/io/FiberRefs";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @tsplus getter fncts.io.IO diffFiberRefs
|
5
|
+
*/
|
6
|
+
export function diffFiberRefs<R, E, A>(
|
7
|
+
self: IO<R, E, A>,
|
8
|
+
__tsplusTrace?: string,
|
9
|
+
): IO<R, E, readonly [FiberRefsPatch, A]> {
|
10
|
+
return self.summarized(IO.getFiberRefs(), FiberRefsPatch.diff);
|
11
|
+
}
|
package/_src/IO/api/memoize.ts
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
import type { FiberRefsPatch } from "@fncts/io/FiberRefs";
|
2
|
+
|
1
3
|
/**
|
2
4
|
* @tsplus getter fncts.io.IO memoize
|
3
5
|
*/
|
4
6
|
export function memoize<R, E, A>(self: IO<R, E, A>, __tsplusTrace?: string): UIO<IO<R, E, A>> {
|
5
7
|
return Do((_) => {
|
6
|
-
const future = _(Future.make<E, A>());
|
7
|
-
const complete = _(
|
8
|
-
return complete > future.await;
|
8
|
+
const future = _(Future.make<E, readonly [FiberRefsPatch, A]>());
|
9
|
+
const complete = _(self.diffFiberRefs.fulfill(future).once);
|
10
|
+
return complete > future.await.flatMap(([patch, a]) => IO.patchFiberRefs(patch).as(a));
|
9
11
|
});
|
10
12
|
}
|
package/_src/IO/api/timeout.ts
CHANGED
@@ -27,6 +27,14 @@ export function timeoutTo<A, B, B1>(duration: Lazy<Duration>, b: Lazy<B>, f: (a:
|
|
27
27
|
};
|
28
28
|
}
|
29
29
|
|
30
|
+
/**
|
31
|
+
* @tsplus pipeable fncts.io.IO timeoutFail
|
32
|
+
*/
|
33
|
+
export function timeoutFail<E1>(duration: Lazy<Duration>, b: Lazy<E1>) {
|
34
|
+
return <R, E, A>(self: IO<R, E, A>): IO<R, E | E1, A> =>
|
35
|
+
self.timeoutTo(duration, IO.fail(b), (a) => IO.succeedNow(a)).flatten;
|
36
|
+
}
|
37
|
+
|
30
38
|
/**
|
31
39
|
* @tsplus pipeable fncts.io.IO timeout
|
32
40
|
*/
|
package/_src/IO/api.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { Running } from "../FiberStatus.js";
|
2
|
+
import type { ShowOptions } from "@fncts/base/data/Showable.js";
|
2
3
|
import type * as P from "@fncts/base/typeclass";
|
3
4
|
import type { _E, _R } from "@fncts/base/types";
|
4
5
|
import type { FiberRuntime } from "@fncts/io/Fiber/FiberRuntime";
|
@@ -6,6 +7,7 @@ import type { RuntimeFlags } from "@fncts/io/RuntimeFlags";
|
|
6
7
|
|
7
8
|
import { IOError } from "@fncts/base/data/exceptions";
|
8
9
|
import { identity, pipe, tuple } from "@fncts/base/data/function";
|
10
|
+
import { showWithOptions } from "@fncts/base/data/Showable";
|
9
11
|
import { IOPrimitive, IOTag } from "@fncts/io/IO/definition";
|
10
12
|
import { IO } from "@fncts/io/IO/definition";
|
11
13
|
|
@@ -122,10 +124,10 @@ export function bitap<E, A, R1, E1, R2, E2>(
|
|
122
124
|
return <R>(self: IO<R, E, A>): IO<R | R1 | R2, E | E1 | E2, A> => {
|
123
125
|
return self.matchCauseIO(
|
124
126
|
(cause) =>
|
125
|
-
cause.failureOrCause.match(
|
126
|
-
|
127
|
-
|
128
|
-
|
127
|
+
cause.failureOrCause.match(
|
128
|
+
(e) => onFailure(e).flatMap(() => IO.failCauseNow(cause)),
|
129
|
+
() => IO.failCauseNow(cause),
|
130
|
+
),
|
129
131
|
(a) => onSuccess(a).zipRight(IO.succeedNow(a)),
|
130
132
|
);
|
131
133
|
};
|
@@ -200,8 +202,7 @@ export function catchAllCause<R, E, A, R1, E1, A1>(f: (_: Cause<E>) => IO<R1, E1
|
|
200
202
|
export function catchJust<E, R1, E1, A1>(f: (e: E) => Maybe<IO<R1, E1, A1>>, __tsplusTrace?: string) {
|
201
203
|
return <R, A>(ma: IO<R, E, A>): IO<R | R1, E | E1, A | A1> => {
|
202
204
|
return ma.matchCauseIO(
|
203
|
-
(cause) =>
|
204
|
-
cause.failureOrCause.match({ Left: (e) => f(e).getOrElse(IO.failCauseNow(cause)), Right: IO.failCauseNow }),
|
205
|
+
(cause) => cause.failureOrCause.match((e) => f(e).getOrElse(IO.failCauseNow(cause)), IO.failCauseNow),
|
205
206
|
IO.succeedNow,
|
206
207
|
);
|
207
208
|
};
|
@@ -318,6 +319,7 @@ export function flatMap<A, R1, E1, B>(f: (a: A) => IO<R1, E1, B>, __tsplusTrace?
|
|
318
319
|
io.i0 = ma;
|
319
320
|
io.i1 = f;
|
320
321
|
io.trace = __tsplusTrace;
|
322
|
+
|
321
323
|
return io;
|
322
324
|
};
|
323
325
|
}
|
@@ -805,7 +807,7 @@ export function forever<R, E, A>(ma: IO<R, E, A>, __tsplusTrace?: string): IO<R,
|
|
805
807
|
* @tsplus static fncts.io.IOOps fromEither
|
806
808
|
*/
|
807
809
|
export function fromEither<E, A>(either: Lazy<Either<E, A>>, __tsplusTrace?: string): IO<never, E, A> {
|
808
|
-
return IO.succeed(either).flatMap((ea) => ea.match(
|
810
|
+
return IO.succeed(either).flatMap((ea) => ea.match(IO.failNow, IO.succeedNow));
|
809
811
|
}
|
810
812
|
|
811
813
|
/**
|
@@ -815,7 +817,7 @@ export function fromEither<E, A>(either: Lazy<Either<E, A>>, __tsplusTrace?: str
|
|
815
817
|
* @tsplus getter fncts.Either toIO
|
816
818
|
*/
|
817
819
|
export function fromEitherNow<E, A>(either: Either<E, A>, __tsplusTrace?: string): IO<never, E, A> {
|
818
|
-
return either.match(
|
820
|
+
return either.match(IO.failNow, IO.succeedNow);
|
819
821
|
}
|
820
822
|
|
821
823
|
/**
|
@@ -958,6 +960,13 @@ export function getOrFailUnit<A>(option: Maybe<A>, __tsplusTrace?: string): FIO<
|
|
958
960
|
return IO.getOrFailWith(option, undefined);
|
959
961
|
}
|
960
962
|
|
963
|
+
/**
|
964
|
+
* @tsplus static fncts.io.IOOps getFiberRefs
|
965
|
+
*/
|
966
|
+
export function getFiberRefs(__tsplusTrace?: string): UIO<FiberRefs> {
|
967
|
+
return IO.withFiberRuntime((fiberState) => IO.succeed(fiberState.getFiberRefs()));
|
968
|
+
}
|
969
|
+
|
961
970
|
/**
|
962
971
|
* Creates an `IO` that halts with the specified lazily-evaluated defect.
|
963
972
|
* This method can be used for terminating a fiber because a defect has been
|
@@ -1091,6 +1100,13 @@ export function log(message: Lazy<string>, __tsplusTrace?: string): UIO<void> {
|
|
1091
1100
|
});
|
1092
1101
|
}
|
1093
1102
|
|
1103
|
+
/**
|
1104
|
+
* @tsplus static fncts.io.IOOps show
|
1105
|
+
*/
|
1106
|
+
export function show(message: Lazy<unknown>, options?: Partial<ShowOptions>, __tsplusTrace?: string): UIO<void> {
|
1107
|
+
return IO.log(showWithOptions(message, options));
|
1108
|
+
}
|
1109
|
+
|
1094
1110
|
/**
|
1095
1111
|
* Loops with the specified effectual function, collecting the results into a
|
1096
1112
|
* list. The moral equivalent of:
|
@@ -1250,10 +1266,7 @@ export function matchIO<R1, R2, E, E1, E2, A, A1, A2>(
|
|
1250
1266
|
__tsplusTrace?: string,
|
1251
1267
|
) {
|
1252
1268
|
return <R>(self: IO<R, E, A>): IO<R | R1 | R2, E1 | E2, A1 | A2> => {
|
1253
|
-
return self.matchCauseIO(
|
1254
|
-
(cause) => cause.failureOrCause.match({ Left: onFailure, Right: IO.failCauseNow }),
|
1255
|
-
onSuccess,
|
1256
|
-
);
|
1269
|
+
return self.matchCauseIO((cause) => cause.failureOrCause.match(onFailure, IO.failCauseNow), onSuccess);
|
1257
1270
|
};
|
1258
1271
|
}
|
1259
1272
|
|
@@ -1285,7 +1298,7 @@ export function matchTraceIO<E, A, R1, E1, A1, R2, E2, A2>(
|
|
1285
1298
|
) {
|
1286
1299
|
return <R>(ma: IO<R, E, A>): IO<R | R1 | R2, E1 | E2, A1 | A2> => {
|
1287
1300
|
return ma.matchCauseIO(
|
1288
|
-
(cause) => cause.failureTraceOrCause.match(
|
1301
|
+
(cause) => cause.failureTraceOrCause.match(([e, trace]) => onFailure(e, trace), IO.failCauseNow),
|
1289
1302
|
onSuccess,
|
1290
1303
|
);
|
1291
1304
|
};
|
@@ -1775,7 +1788,7 @@ export function tryCatch<E, A>(effect: Lazy<A>, onThrow: (error: unknown) => E,
|
|
1775
1788
|
} catch (u) {
|
1776
1789
|
return IO.withFiberRuntime((fiberState) => {
|
1777
1790
|
if (!fiberState.isFatal(u)) {
|
1778
|
-
throw new IOError(Cause.fail(u));
|
1791
|
+
throw new IOError(Cause.fail(onThrow(u)));
|
1779
1792
|
} else {
|
1780
1793
|
throw u;
|
1781
1794
|
}
|
@@ -1790,7 +1803,7 @@ export function tryCatch<E, A>(effect: Lazy<A>, onThrow: (error: unknown) => E,
|
|
1790
1803
|
* @tsplus getter fncts.io.IO absolve
|
1791
1804
|
*/
|
1792
1805
|
export function absolve<R, E, E1, A>(ma: IO<R, E, Either<E1, A>>, __tsplusTrace?: string): IO<R, E | E1, A> {
|
1793
|
-
return ma.flatMap((ea) => ea.match(
|
1806
|
+
return ma.flatMap((ea) => ea.match(IO.failNow, IO.succeedNow));
|
1794
1807
|
}
|
1795
1808
|
|
1796
1809
|
/**
|
@@ -1828,10 +1841,10 @@ export function tapError<E, R1, E1>(f: (e: E) => IO<R1, E1, any>, __tsplusTrace?
|
|
1828
1841
|
return <R, A>(self: IO<R, E, A>) =>
|
1829
1842
|
self.matchCauseIO(
|
1830
1843
|
(cause) =>
|
1831
|
-
cause.failureOrCause.match(
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1844
|
+
cause.failureOrCause.match(
|
1845
|
+
(e) => f(e).flatMap(() => IO.failCauseNow(cause)),
|
1846
|
+
(_) => IO.failCauseNow(cause),
|
1847
|
+
),
|
1835
1848
|
IO.succeedNow,
|
1836
1849
|
);
|
1837
1850
|
}
|
package/_src/IO/definition.ts
CHANGED
@@ -51,7 +51,7 @@ declare module "@fncts/base/data/Exit/definition" {
|
|
51
51
|
}
|
52
52
|
|
53
53
|
declare module "@fncts/base/data/Tag/definition" {
|
54
|
-
interface Tag<T, Identifier = T> extends IO<
|
54
|
+
export interface Tag<T, Identifier = T> extends IO<T, never, T> {}
|
55
55
|
}
|
56
56
|
|
57
57
|
/**
|
@@ -100,11 +100,12 @@ export const enum IOTag {
|
|
100
100
|
Commit,
|
101
101
|
RevertFlags,
|
102
102
|
UpdateTrace,
|
103
|
+
External,
|
103
104
|
}
|
104
105
|
|
105
106
|
export type IOOp<Tag extends string | number, Body = {}> = IO<never, never, never> &
|
106
107
|
Body & {
|
107
|
-
readonly
|
108
|
+
readonly _ioOpCode: Tag;
|
108
109
|
};
|
109
110
|
|
110
111
|
export class IOPrimitive {
|
@@ -112,8 +113,8 @@ export class IOPrimitive {
|
|
112
113
|
public i1: any = undefined;
|
113
114
|
public i2: any = undefined;
|
114
115
|
public trace: string | undefined = undefined;
|
115
|
-
[IOTypeId] = IOTypeId;
|
116
|
-
constructor(readonly
|
116
|
+
readonly [IOTypeId]: IOTypeId = IOTypeId;
|
117
|
+
constructor(readonly _ioOpCode: unknown) {}
|
117
118
|
}
|
118
119
|
|
119
120
|
export function isIO(u: unknown): u is IO<any, any, any> {
|
@@ -257,6 +258,7 @@ export type Primitive =
|
|
257
258
|
| WhileLoop
|
258
259
|
| YieldNow
|
259
260
|
| Fail
|
261
|
+
| External<any, any, any>
|
260
262
|
| STM<any, any, any>
|
261
263
|
| Left<any>
|
262
264
|
| Right<any>
|
@@ -277,3 +279,17 @@ export function concrete(io: IO<any, any, any>): Primitive {
|
|
277
279
|
export type EvaluationStep = OnSuccessAndFailure | OnFailure | OnSuccess;
|
278
280
|
|
279
281
|
export type Canceler<R> = URIO<R, void>;
|
282
|
+
|
283
|
+
export abstract class External<R, E, A> extends IOPrimitive implements IO<R, E, A> {
|
284
|
+
declare _ioOpCode: IOTag.External;
|
285
|
+
declare [IOVariance]: {
|
286
|
+
_R: () => R;
|
287
|
+
_E: () => E;
|
288
|
+
_A: () => A;
|
289
|
+
};
|
290
|
+
|
291
|
+
constructor() {
|
292
|
+
super(IOTag.External);
|
293
|
+
}
|
294
|
+
abstract toIO: IO<R, E, A>;
|
295
|
+
}
|