effect 3.8.5 → 3.9.1
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/dist/cjs/Array.js +24 -3
- package/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/Context.js.map +1 -1
- package/dist/cjs/Effect.js +122 -35
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/HashMap.js.map +1 -1
- package/dist/cjs/Layer.js.map +1 -1
- package/dist/cjs/ManagedRuntime.js +16 -1
- package/dist/cjs/ManagedRuntime.js.map +1 -1
- package/dist/cjs/Pool.js.map +1 -1
- package/dist/cjs/Predicate.js +18 -2
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/RegExp.js +20 -1
- package/dist/cjs/RegExp.js.map +1 -1
- package/dist/cjs/Resource.js.map +1 -1
- package/dist/cjs/ScopedRef.js.map +1 -1
- package/dist/cjs/Tuple.js +21 -2
- package/dist/cjs/Tuple.js.map +1 -1
- package/dist/cjs/Unify.js.map +1 -1
- package/dist/cjs/internal/context.js +0 -1
- package/dist/cjs/internal/context.js.map +1 -1
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/effect/circular.js +5 -1
- package/dist/cjs/internal/effect/circular.js.map +1 -1
- package/dist/cjs/internal/layer.js +33 -19
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/managedRuntime/circular.js +10 -0
- package/dist/cjs/internal/managedRuntime/circular.js.map +1 -0
- package/dist/cjs/internal/managedRuntime.js +23 -9
- package/dist/cjs/internal/managedRuntime.js.map +1 -1
- package/dist/cjs/internal/pool.js +6 -1
- package/dist/cjs/internal/pool.js.map +1 -1
- package/dist/cjs/internal/resource.js +15 -5
- package/dist/cjs/internal/resource.js.map +1 -1
- package/dist/cjs/internal/scopedRef.js +11 -8
- package/dist/cjs/internal/scopedRef.js.map +1 -1
- package/dist/cjs/internal/stm/core.js +1 -2
- package/dist/cjs/internal/stm/core.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +51 -2
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/Context.d.ts +2 -3
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Deferred.d.ts +1 -1
- package/dist/dts/Deferred.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +233 -10
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/HashMap.d.ts +15 -0
- package/dist/dts/HashMap.d.ts.map +1 -1
- package/dist/dts/Layer.d.ts +46 -5
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/ManagedRuntime.d.ts +41 -2
- package/dist/dts/ManagedRuntime.d.ts.map +1 -1
- package/dist/dts/Pool.d.ts +21 -1
- package/dist/dts/Pool.d.ts.map +1 -1
- package/dist/dts/Predicate.d.ts +15 -0
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Queue.d.ts +2 -2
- package/dist/dts/Queue.d.ts.map +1 -1
- package/dist/dts/RegExp.d.ts +12 -2
- package/dist/dts/RegExp.d.ts.map +1 -1
- package/dist/dts/Resource.d.ts +21 -1
- package/dist/dts/Resource.d.ts.map +1 -1
- package/dist/dts/ScopedRef.d.ts +21 -1
- package/dist/dts/ScopedRef.d.ts.map +1 -1
- package/dist/dts/Tuple.d.ts +59 -0
- package/dist/dts/Tuple.d.ts.map +1 -1
- package/dist/dts/Types.d.ts +39 -0
- package/dist/dts/Types.d.ts.map +1 -1
- package/dist/dts/Unify.d.ts +8 -13
- package/dist/dts/Unify.d.ts.map +1 -1
- package/dist/dts/internal/layer.d.ts.map +1 -1
- package/dist/dts/internal/managedRuntime/circular.d.ts +2 -0
- package/dist/dts/internal/managedRuntime/circular.d.ts.map +1 -0
- package/dist/esm/Array.js +21 -0
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/Context.js.map +1 -1
- package/dist/esm/Effect.js +116 -30
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/HashMap.js.map +1 -1
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/ManagedRuntime.js +15 -0
- package/dist/esm/ManagedRuntime.js.map +1 -1
- package/dist/esm/Pool.js.map +1 -1
- package/dist/esm/Predicate.js +15 -0
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/RegExp.js +16 -0
- package/dist/esm/RegExp.js.map +1 -1
- package/dist/esm/Resource.js.map +1 -1
- package/dist/esm/ScopedRef.js.map +1 -1
- package/dist/esm/Tuple.js +19 -0
- package/dist/esm/Tuple.js.map +1 -1
- package/dist/esm/Unify.js.map +1 -1
- package/dist/esm/internal/context.js +0 -1
- package/dist/esm/internal/context.js.map +1 -1
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/effect/circular.js +5 -1
- package/dist/esm/internal/effect/circular.js.map +1 -1
- package/dist/esm/internal/layer.js +32 -18
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/managedRuntime/circular.js +4 -0
- package/dist/esm/internal/managedRuntime/circular.js.map +1 -0
- package/dist/esm/internal/managedRuntime.js +21 -8
- package/dist/esm/internal/managedRuntime.js.map +1 -1
- package/dist/esm/internal/pool.js +6 -1
- package/dist/esm/internal/pool.js.map +1 -1
- package/dist/esm/internal/resource.js +15 -5
- package/dist/esm/internal/resource.js.map +1 -1
- package/dist/esm/internal/scopedRef.js +11 -8
- package/dist/esm/internal/scopedRef.js.map +1 -1
- package/dist/esm/internal/stm/core.js +1 -2
- package/dist/esm/internal/stm/core.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Array.ts +68 -4
- package/src/Context.ts +2 -3
- package/src/Deferred.ts +1 -1
- package/src/Effect.ts +435 -56
- package/src/HashMap.ts +16 -0
- package/src/Layer.ts +49 -8
- package/src/ManagedRuntime.ts +46 -2
- package/src/Pool.ts +26 -1
- package/src/Predicate.ts +16 -0
- package/src/Queue.ts +2 -2
- package/src/RegExp.ts +17 -0
- package/src/Resource.ts +22 -1
- package/src/ScopedRef.ts +22 -1
- package/src/Tuple.ts +66 -0
- package/src/Types.ts +41 -0
- package/src/Unify.ts +9 -14
- package/src/internal/context.ts +0 -1
- package/src/internal/core-effect.ts +7 -7
- package/src/internal/effect/circular.ts +8 -2
- package/src/internal/layer.ts +105 -38
- package/src/internal/managedRuntime/circular.ts +6 -0
- package/src/internal/managedRuntime.ts +36 -22
- package/src/internal/pool.ts +7 -1
- package/src/internal/resource.ts +16 -5
- package/src/internal/scopedRef.ts +12 -8
- package/src/internal/stm/core.ts +2 -3
- package/src/internal/version.ts +1 -1
package/src/internal/layer.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { LazyArg } from "../Function.js"
|
|
|
10
10
|
import { dual, pipe } from "../Function.js"
|
|
11
11
|
import * as HashMap from "../HashMap.js"
|
|
12
12
|
import type * as Layer from "../Layer.js"
|
|
13
|
+
import type * as ManagedRuntime from "../ManagedRuntime.js"
|
|
13
14
|
import { pipeArguments } from "../Pipeable.js"
|
|
14
15
|
import { hasProperty } from "../Predicate.js"
|
|
15
16
|
import type * as Runtime from "../Runtime.js"
|
|
@@ -23,6 +24,7 @@ import * as effect from "./core-effect.js"
|
|
|
23
24
|
import * as core from "./core.js"
|
|
24
25
|
import * as circular from "./effect/circular.js"
|
|
25
26
|
import * as fiberRuntime from "./fiberRuntime.js"
|
|
27
|
+
import * as circularManagedRuntime from "./managedRuntime/circular.js"
|
|
26
28
|
import * as EffectOpCodes from "./opCodes/effect.js"
|
|
27
29
|
import * as OpCodes from "./opCodes/layer.js"
|
|
28
30
|
import * as ref from "./ref.js"
|
|
@@ -49,7 +51,7 @@ const layerVariance = {
|
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
/** @internal */
|
|
52
|
-
const proto = {
|
|
54
|
+
export const proto = {
|
|
53
55
|
[LayerTypeId]: layerVariance,
|
|
54
56
|
pipe() {
|
|
55
57
|
return pipeArguments(this, arguments)
|
|
@@ -79,7 +81,7 @@ export type Primitive =
|
|
|
79
81
|
|
|
80
82
|
/** @internal */
|
|
81
83
|
export type Op<Tag extends string, Body = {}> = Layer.Layer<unknown, unknown, unknown> & Body & {
|
|
82
|
-
readonly
|
|
84
|
+
readonly _op_layer: Tag
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
/** @internal */
|
|
@@ -165,7 +167,7 @@ export const isLayer = (u: unknown): u is Layer.Layer<unknown, unknown, unknown>
|
|
|
165
167
|
|
|
166
168
|
/** @internal */
|
|
167
169
|
export const isFresh = <RIn, E, ROut>(self: Layer.Layer<ROut, E, RIn>): boolean => {
|
|
168
|
-
return (self as Primitive).
|
|
170
|
+
return (self as Primitive)._op_layer === OpCodes.OP_FRESH
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
// -----------------------------------------------------------------------------
|
|
@@ -356,7 +358,7 @@ const makeBuilder = <RIn, E, ROut>(
|
|
|
356
358
|
inMemoMap = false
|
|
357
359
|
): Effect.Effect<(memoMap: Layer.MemoMap) => Effect.Effect<Context.Context<ROut>, E, RIn>> => {
|
|
358
360
|
const op = self as Primitive
|
|
359
|
-
switch (op.
|
|
361
|
+
switch (op._op_layer) {
|
|
360
362
|
case "Locally": {
|
|
361
363
|
return core.sync(() => (memoMap: Layer.MemoMap) => op.f(memoMap.getOrElseMemoize(op.self, scope)))
|
|
362
364
|
}
|
|
@@ -487,7 +489,7 @@ export const extendScope = <RIn, E, ROut>(
|
|
|
487
489
|
self: Layer.Layer<ROut, E, RIn>
|
|
488
490
|
): Layer.Layer<ROut, E, RIn | Scope.Scope> => {
|
|
489
491
|
const extendScope = Object.create(proto)
|
|
490
|
-
extendScope.
|
|
492
|
+
extendScope._op_layer = OpCodes.OP_EXTEND_SCOPE
|
|
491
493
|
extendScope.layer = self
|
|
492
494
|
return extendScope
|
|
493
495
|
}
|
|
@@ -533,7 +535,7 @@ export const flatten = dual<
|
|
|
533
535
|
/** @internal */
|
|
534
536
|
export const fresh = <A, E, R>(self: Layer.Layer<A, E, R>): Layer.Layer<A, E, R> => {
|
|
535
537
|
const fresh = Object.create(proto)
|
|
536
|
-
fresh.
|
|
538
|
+
fresh._op_layer = OpCodes.OP_FRESH
|
|
537
539
|
fresh.layer = self
|
|
538
540
|
return fresh
|
|
539
541
|
}
|
|
@@ -565,7 +567,7 @@ export function fromEffectContext<A, E, R>(
|
|
|
565
567
|
effect: Effect.Effect<Context.Context<A>, E, R>
|
|
566
568
|
): Layer.Layer<A, E, R> {
|
|
567
569
|
const fromEffect = Object.create(proto)
|
|
568
|
-
fromEffect.
|
|
570
|
+
fromEffect._op_layer = OpCodes.OP_FROM_EFFECT
|
|
569
571
|
fromEffect.effect = effect
|
|
570
572
|
return fromEffect
|
|
571
573
|
}
|
|
@@ -587,7 +589,7 @@ export const locallyEffect = dual<
|
|
|
587
589
|
) => Layer.Layer<ROut2, E2, RIn2>
|
|
588
590
|
>(2, (self, f) => {
|
|
589
591
|
const locally = Object.create(proto)
|
|
590
|
-
locally.
|
|
592
|
+
locally._op_layer = "Locally"
|
|
591
593
|
locally.self = self
|
|
592
594
|
locally.f = f
|
|
593
595
|
return locally
|
|
@@ -658,7 +660,7 @@ export const matchCause = dual<
|
|
|
658
660
|
) => Layer.Layer<A2 & A3, E2 | E3, R | R2 | R3>
|
|
659
661
|
>(2, (self, { onFailure, onSuccess }) => {
|
|
660
662
|
const fold = Object.create(proto)
|
|
661
|
-
fold.
|
|
663
|
+
fold._op_layer = OpCodes.OP_FOLD
|
|
662
664
|
fold.layer = self
|
|
663
665
|
fold.failureK = onFailure
|
|
664
666
|
fold.successK = onSuccess
|
|
@@ -866,7 +868,7 @@ export const scopedContext = <A, E, R>(
|
|
|
866
868
|
effect: Effect.Effect<Context.Context<A>, E, R>
|
|
867
869
|
): Layer.Layer<A, E, Exclude<R, Scope.Scope>> => {
|
|
868
870
|
const scoped = Object.create(proto)
|
|
869
|
-
scoped.
|
|
871
|
+
scoped._op_layer = OpCodes.OP_SCOPED
|
|
870
872
|
scoped.effect = effect
|
|
871
873
|
return scoped
|
|
872
874
|
}
|
|
@@ -920,7 +922,7 @@ export const suspend = <RIn, E, ROut>(
|
|
|
920
922
|
evaluate: LazyArg<Layer.Layer<ROut, E, RIn>>
|
|
921
923
|
): Layer.Layer<ROut, E, RIn> => {
|
|
922
924
|
const suspend = Object.create(proto)
|
|
923
|
-
suspend.
|
|
925
|
+
suspend._op_layer = OpCodes.OP_SUSPEND
|
|
924
926
|
suspend.evaluate = evaluate
|
|
925
927
|
return suspend
|
|
926
928
|
}
|
|
@@ -1024,29 +1026,52 @@ export const toRuntimeWithMemoMap = dual<
|
|
|
1024
1026
|
|
|
1025
1027
|
/** @internal */
|
|
1026
1028
|
export const provide = dual<
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1029
|
+
{
|
|
1030
|
+
<RIn, E, ROut>(
|
|
1031
|
+
that: Layer.Layer<ROut, E, RIn>
|
|
1032
|
+
): <RIn2, E2, ROut2>(
|
|
1033
|
+
self: Layer.Layer<ROut2, E2, RIn2>
|
|
1034
|
+
) => Layer.Layer<ROut2, E | E2, RIn | Exclude<RIn2, ROut>>
|
|
1035
|
+
<const Layers extends [Layer.Layer.Any, ...Array<Layer.Layer.Any>]>(
|
|
1036
|
+
that: Layers
|
|
1037
|
+
): <A, E, R>(
|
|
1038
|
+
self: Layer.Layer<A, E, R>
|
|
1039
|
+
) => Layer.Layer<
|
|
1040
|
+
A,
|
|
1041
|
+
E | { [k in keyof Layers]: Layer.Layer.Error<Layers[k]> }[number],
|
|
1042
|
+
| { [k in keyof Layers]: Layer.Layer.Context<Layers[k]> }[number]
|
|
1043
|
+
| Exclude<R, { [k in keyof Layers]: Layer.Layer.Success<Layers[k]> }[number]>
|
|
1044
|
+
>
|
|
1045
|
+
},
|
|
1046
|
+
{
|
|
1047
|
+
<RIn2, E2, ROut2, RIn, E, ROut>(
|
|
1048
|
+
self: Layer.Layer<ROut2, E2, RIn2>,
|
|
1049
|
+
that: Layer.Layer<ROut, E, RIn>
|
|
1050
|
+
): Layer.Layer<ROut2, E | E2, RIn | Exclude<RIn2, ROut>>
|
|
1051
|
+
<A, E, R, const Layers extends [Layer.Layer.Any, ...Array<Layer.Layer.Any>]>(
|
|
1052
|
+
self: Layer.Layer<A, E, R>,
|
|
1053
|
+
that: Layers
|
|
1054
|
+
): Layer.Layer<
|
|
1055
|
+
A,
|
|
1056
|
+
E | { [k in keyof Layers]: Layer.Layer.Error<Layers[k]> }[number],
|
|
1057
|
+
| { [k in keyof Layers]: Layer.Layer.Context<Layers[k]> }[number]
|
|
1058
|
+
| Exclude<R, { [k in keyof Layers]: Layer.Layer.Success<Layers[k]> }[number]>
|
|
1059
|
+
>
|
|
1060
|
+
}
|
|
1061
|
+
>(2, (
|
|
1062
|
+
self: Layer.Layer.Any,
|
|
1063
|
+
that: Layer.Layer.Any | ReadonlyArray<Layer.Layer.Any>
|
|
1039
1064
|
) =>
|
|
1040
1065
|
suspend(() => {
|
|
1041
1066
|
const provideTo = Object.create(proto)
|
|
1042
|
-
provideTo.
|
|
1067
|
+
provideTo._op_layer = OpCodes.OP_PROVIDE
|
|
1043
1068
|
provideTo.first = Object.create(proto, {
|
|
1044
|
-
|
|
1045
|
-
first: { value: context
|
|
1046
|
-
second: { value:
|
|
1047
|
-
zipK: { value: (a: Context.Context<
|
|
1069
|
+
_op_layer: { value: OpCodes.OP_PROVIDE_MERGE, enumerable: true },
|
|
1070
|
+
first: { value: context(), enumerable: true },
|
|
1071
|
+
second: { value: Array.isArray(that) ? mergeAll(...that as any) : that },
|
|
1072
|
+
zipK: { value: (a: Context.Context<any>, b: Context.Context<any>) => pipe(a, Context.merge(b)) }
|
|
1048
1073
|
})
|
|
1049
|
-
provideTo.second =
|
|
1074
|
+
provideTo.second = self
|
|
1050
1075
|
return provideTo
|
|
1051
1076
|
}))
|
|
1052
1077
|
|
|
@@ -1063,7 +1088,7 @@ export const provideMerge = dual<
|
|
|
1063
1088
|
) => Layer.Layer<ROut | ROut2, E2 | E, RIn | Exclude<RIn2, ROut>>
|
|
1064
1089
|
>(2, <RIn2, E2, ROut2, RIn, E, ROut>(that: Layer.Layer<ROut2, E2, RIn2>, self: Layer.Layer<ROut, E, RIn>) => {
|
|
1065
1090
|
const zipWith = Object.create(proto)
|
|
1066
|
-
zipWith.
|
|
1091
|
+
zipWith._op_layer = OpCodes.OP_PROVIDE_MERGE
|
|
1067
1092
|
zipWith.first = self
|
|
1068
1093
|
zipWith.second = provide(that, self)
|
|
1069
1094
|
zipWith.zipK = (a: Context.Context<ROut>, b: Context.Context<ROut2>): Context.Context<ROut | ROut2> => {
|
|
@@ -1086,7 +1111,7 @@ export const zipWith = dual<
|
|
|
1086
1111
|
>(3, (self, that, f) =>
|
|
1087
1112
|
suspend(() => {
|
|
1088
1113
|
const zipWith = Object.create(proto)
|
|
1089
|
-
zipWith.
|
|
1114
|
+
zipWith._op_layer = OpCodes.OP_ZIP_WITH
|
|
1090
1115
|
zipWith.first = self
|
|
1091
1116
|
zipWith.second = that
|
|
1092
1117
|
zipWith.zipK = f
|
|
@@ -1291,6 +1316,16 @@ const provideSomeRuntime = dual<
|
|
|
1291
1316
|
/** @internal */
|
|
1292
1317
|
export const effect_provide = dual<
|
|
1293
1318
|
{
|
|
1319
|
+
<const Layers extends [Layer.Layer.Any, ...Array<Layer.Layer.Any>]>(
|
|
1320
|
+
layers: Layers
|
|
1321
|
+
): <A, E, R>(
|
|
1322
|
+
self: Effect.Effect<A, E, R>
|
|
1323
|
+
) => Effect.Effect<
|
|
1324
|
+
A,
|
|
1325
|
+
E | { [k in keyof Layers]: Layer.Layer.Error<Layers[k]> }[number],
|
|
1326
|
+
| { [k in keyof Layers]: Layer.Layer.Context<Layers[k]> }[number]
|
|
1327
|
+
| Exclude<R, { [k in keyof Layers]: Layer.Layer.Success<Layers[k]> }[number]>
|
|
1328
|
+
>
|
|
1294
1329
|
<ROut, E2, RIn>(
|
|
1295
1330
|
layer: Layer.Layer<ROut, E2, RIn>
|
|
1296
1331
|
): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | E2, RIn | Exclude<R, ROut>>
|
|
@@ -1300,8 +1335,20 @@ export const effect_provide = dual<
|
|
|
1300
1335
|
<R2>(
|
|
1301
1336
|
runtime: Runtime.Runtime<R2>
|
|
1302
1337
|
): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, R2>>
|
|
1338
|
+
<E2, R2>(
|
|
1339
|
+
managedRuntime: ManagedRuntime.ManagedRuntime<R2, E2>
|
|
1340
|
+
): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | E2, Exclude<R, R2>>
|
|
1303
1341
|
},
|
|
1304
1342
|
{
|
|
1343
|
+
<A, E, R, const Layers extends [Layer.Layer.Any, ...Array<Layer.Layer.Any>]>(
|
|
1344
|
+
self: Effect.Effect<A, E, R>,
|
|
1345
|
+
layers: Layers
|
|
1346
|
+
): Effect.Effect<
|
|
1347
|
+
A,
|
|
1348
|
+
E | { [k in keyof Layers]: Layer.Layer.Error<Layers[k]> }[number],
|
|
1349
|
+
| { [k in keyof Layers]: Layer.Layer.Context<Layers[k]> }[number]
|
|
1350
|
+
| Exclude<R, { [k in keyof Layers]: Layer.Layer.Success<Layers[k]> }[number]>
|
|
1351
|
+
>
|
|
1305
1352
|
<A, E, R, ROut, E2, RIn>(
|
|
1306
1353
|
self: Effect.Effect<A, E, R>,
|
|
1307
1354
|
layer: Layer.Layer<ROut, E2, RIn>
|
|
@@ -1314,16 +1361,36 @@ export const effect_provide = dual<
|
|
|
1314
1361
|
self: Effect.Effect<A, E, R>,
|
|
1315
1362
|
runtime: Runtime.Runtime<R2>
|
|
1316
1363
|
): Effect.Effect<A, E, Exclude<R, R2>>
|
|
1364
|
+
<A, E, E2, R, R2>(
|
|
1365
|
+
self: Effect.Effect<A, E, R>,
|
|
1366
|
+
managedRuntime: ManagedRuntime.ManagedRuntime<R2, E2>
|
|
1367
|
+
): Effect.Effect<A, E | E2, Exclude<R, R2>>
|
|
1317
1368
|
}
|
|
1318
1369
|
>(
|
|
1319
1370
|
2,
|
|
1320
1371
|
<A, E, R, ROut>(
|
|
1321
1372
|
self: Effect.Effect<A, E, R>,
|
|
1322
|
-
source:
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1373
|
+
source:
|
|
1374
|
+
| Layer.Layer<ROut, any, any>
|
|
1375
|
+
| Context.Context<ROut>
|
|
1376
|
+
| Runtime.Runtime<ROut>
|
|
1377
|
+
| ManagedRuntime.ManagedRuntime<ROut, any>
|
|
1378
|
+
| Array<Layer.Layer.Any>
|
|
1379
|
+
): Effect.Effect<any, any, Exclude<R, ROut>> => {
|
|
1380
|
+
if (Array.isArray(source)) {
|
|
1381
|
+
// @ts-expect-error
|
|
1382
|
+
return provideSomeLayer(self, mergeAll(...source))
|
|
1383
|
+
} else if (isLayer(source)) {
|
|
1384
|
+
return provideSomeLayer(self, source as Layer.Layer<ROut, any, any>)
|
|
1385
|
+
} else if (Context.isContext(source)) {
|
|
1386
|
+
return core.provideSomeContext(self, source)
|
|
1387
|
+
} else if (circularManagedRuntime.TypeId in source) {
|
|
1388
|
+
return core.flatMap(
|
|
1389
|
+
(source as ManagedRuntime.ManagedRuntime<ROut, any>).runtimeEffect,
|
|
1390
|
+
(rt) => provideSomeRuntime(self, rt)
|
|
1391
|
+
)
|
|
1392
|
+
} else {
|
|
1393
|
+
return provideSomeRuntime(self, source as Runtime.Runtime<ROut>)
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1329
1396
|
)
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import type * as Effect from "../Effect.js"
|
|
2
|
+
import * as Effectable from "../Effectable.js"
|
|
2
3
|
import type { Exit } from "../Exit.js"
|
|
3
4
|
import type * as Fiber from "../Fiber.js"
|
|
4
5
|
import type * as Layer from "../Layer.js"
|
|
5
|
-
import type
|
|
6
|
+
import type * as M from "../ManagedRuntime.js"
|
|
6
7
|
import { pipeArguments } from "../Pipeable.js"
|
|
8
|
+
import { hasProperty } from "../Predicate.js"
|
|
7
9
|
import type * as Runtime from "../Runtime.js"
|
|
8
10
|
import * as Scope from "../Scope.js"
|
|
9
11
|
import * as effect from "./core-effect.js"
|
|
10
12
|
import * as core from "./core.js"
|
|
11
13
|
import * as fiberRuntime from "./fiberRuntime.js"
|
|
12
14
|
import * as internalLayer from "./layer.js"
|
|
15
|
+
import * as circular from "./managedRuntime/circular.js"
|
|
13
16
|
import * as internalRuntime from "./runtime.js"
|
|
14
17
|
|
|
15
|
-
interface ManagedRuntimeImpl<R, E> extends ManagedRuntime<R, E> {
|
|
18
|
+
interface ManagedRuntimeImpl<R, E> extends M.ManagedRuntime<R, E> {
|
|
16
19
|
readonly scope: Scope.CloseableScope
|
|
17
20
|
cachedRuntime: Runtime.Runtime<R> | undefined
|
|
18
21
|
}
|
|
19
22
|
|
|
23
|
+
/** @internal */
|
|
24
|
+
export const isManagedRuntime = (u: unknown): u is M.ManagedRuntime<unknown, unknown> => hasProperty(u, circular.TypeId)
|
|
25
|
+
|
|
20
26
|
function provide<R, ER, A, E>(
|
|
21
27
|
managed: ManagedRuntimeImpl<R, ER>,
|
|
22
28
|
effect: Effect.Effect<A, E, R>
|
|
@@ -32,34 +38,42 @@ function provide<R, ER, A, E>(
|
|
|
32
38
|
)
|
|
33
39
|
}
|
|
34
40
|
|
|
41
|
+
const ManagedRuntimeProto = {
|
|
42
|
+
...Effectable.CommitPrototype,
|
|
43
|
+
[circular.TypeId]: circular.TypeId,
|
|
44
|
+
pipe() {
|
|
45
|
+
return pipeArguments(this, arguments)
|
|
46
|
+
},
|
|
47
|
+
commit(this: ManagedRuntimeImpl<unknown, unknown>) {
|
|
48
|
+
return this.runtimeEffect
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
35
52
|
/** @internal */
|
|
36
53
|
export const make = <R, ER>(
|
|
37
54
|
layer: Layer.Layer<R, ER, never>,
|
|
38
55
|
memoMap?: Layer.MemoMap
|
|
39
|
-
): ManagedRuntime<R, ER> => {
|
|
56
|
+
): M.ManagedRuntime<R, ER> => {
|
|
40
57
|
memoMap = memoMap ?? internalLayer.unsafeMakeMemoMap()
|
|
41
58
|
const scope = internalRuntime.unsafeRunSyncEffect(fiberRuntime.scopeMake())
|
|
42
|
-
const
|
|
59
|
+
const runtimeEffect = internalRuntime.unsafeRunSyncEffect(
|
|
60
|
+
effect.memoize(
|
|
61
|
+
core.tap(
|
|
62
|
+
Scope.extend(
|
|
63
|
+
internalLayer.toRuntimeWithMemoMap(layer, memoMap),
|
|
64
|
+
scope
|
|
65
|
+
),
|
|
66
|
+
(rt) => {
|
|
67
|
+
self.cachedRuntime = rt
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
const self: ManagedRuntimeImpl<R, ER> = Object.assign(Object.create(ManagedRuntimeProto), {
|
|
43
73
|
memoMap,
|
|
44
74
|
scope,
|
|
45
|
-
runtimeEffect
|
|
46
|
-
.unsafeRunSyncEffect(
|
|
47
|
-
effect.memoize(
|
|
48
|
-
core.tap(
|
|
49
|
-
Scope.extend(
|
|
50
|
-
internalLayer.toRuntimeWithMemoMap(layer, memoMap),
|
|
51
|
-
scope
|
|
52
|
-
),
|
|
53
|
-
(rt) => {
|
|
54
|
-
self.cachedRuntime = rt
|
|
55
|
-
}
|
|
56
|
-
)
|
|
57
|
-
)
|
|
58
|
-
),
|
|
75
|
+
runtimeEffect,
|
|
59
76
|
cachedRuntime: undefined,
|
|
60
|
-
pipe() {
|
|
61
|
-
return pipeArguments(this, arguments)
|
|
62
|
-
},
|
|
63
77
|
runtime() {
|
|
64
78
|
return self.cachedRuntime === undefined ?
|
|
65
79
|
internalRuntime.unsafeRunPromiseEffect(self.runtimeEffect) :
|
|
@@ -110,6 +124,6 @@ export const make = <R, ER>(
|
|
|
110
124
|
internalRuntime.unsafeRunPromiseEffect(provide(self, effect), options) :
|
|
111
125
|
internalRuntime.unsafeRunPromise(self.cachedRuntime)(effect, options)
|
|
112
126
|
}
|
|
113
|
-
}
|
|
127
|
+
})
|
|
114
128
|
return self
|
|
115
129
|
}
|
package/src/internal/pool.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Cause } from "effect/Cause"
|
|
|
2
2
|
import * as Context from "../Context.js"
|
|
3
3
|
import * as Duration from "../Duration.js"
|
|
4
4
|
import type { Effect, Semaphore } from "../Effect.js"
|
|
5
|
+
import * as Effectable from "../Effectable.js"
|
|
5
6
|
import type { Exit } from "../Exit.js"
|
|
6
7
|
import { dual, identity } from "../Function.js"
|
|
7
8
|
import * as Iterable from "../Iterable.js"
|
|
@@ -122,7 +123,7 @@ interface Strategy<A, E> {
|
|
|
122
123
|
readonly reclaim: (pool: PoolImpl<A, E>) => Effect<Option.Option<PoolItem<A, E>>>
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
class PoolImpl<A, E> implements Pool<A, E> {
|
|
126
|
+
class PoolImpl<A, E> extends Effectable.Class<A, E, Scope> implements Pool<A, E> {
|
|
126
127
|
readonly [PoolTypeId]: Pool.Variance<A, E>[PoolTypeId_]
|
|
127
128
|
|
|
128
129
|
isShuttingDown = false
|
|
@@ -140,6 +141,7 @@ class PoolImpl<A, E> implements Pool<A, E> {
|
|
|
140
141
|
readonly strategy: Strategy<A, E>,
|
|
141
142
|
readonly targetUtilization: number
|
|
142
143
|
) {
|
|
144
|
+
super()
|
|
143
145
|
this[PoolTypeId] = poolVariance
|
|
144
146
|
this.semaphore = circular.unsafeMakeSemaphore(concurrency * maxSize)
|
|
145
147
|
}
|
|
@@ -253,6 +255,10 @@ class PoolImpl<A, E> implements Pool<A, E> {
|
|
|
253
255
|
)
|
|
254
256
|
)
|
|
255
257
|
|
|
258
|
+
commit() {
|
|
259
|
+
return this.get
|
|
260
|
+
}
|
|
261
|
+
|
|
256
262
|
readonly get: Effect<A, E, Scope> = core.flatMap(
|
|
257
263
|
core.suspend(() => this.isShuttingDown ? core.interrupt : this.getPoolItem),
|
|
258
264
|
(_) => _.exit
|
package/src/internal/resource.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type * as Resource from "../Resource.js"
|
|
|
4
4
|
import type * as Schedule from "../Schedule.js"
|
|
5
5
|
import type * as Scope from "../Scope.js"
|
|
6
6
|
import * as core from "./core.js"
|
|
7
|
+
import * as effectable from "./effectable.js"
|
|
7
8
|
import * as fiberRuntime from "./fiberRuntime.js"
|
|
8
9
|
import * as _schedule from "./schedule.js"
|
|
9
10
|
import * as scopedRef from "./scopedRef.js"
|
|
@@ -23,6 +24,15 @@ const resourceVariance = {
|
|
|
23
24
|
_A: (_: any) => _
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/** @internal */
|
|
28
|
+
const proto: ThisType<Resource.Resource<any, any>> = {
|
|
29
|
+
...effectable.CommitPrototype,
|
|
30
|
+
commit() {
|
|
31
|
+
return get(this)
|
|
32
|
+
},
|
|
33
|
+
[ResourceTypeId]: resourceVariance
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
/** @internal */
|
|
27
37
|
export const auto = <A, E, R, Out, R2>(
|
|
28
38
|
acquire: Effect.Effect<A, E, R>,
|
|
@@ -46,11 +56,12 @@ export const manual = <A, E, R>(
|
|
|
46
56
|
core.flatMap(core.context<R>(), (env) =>
|
|
47
57
|
pipe(
|
|
48
58
|
scopedRef.fromAcquire(core.exit(acquire)),
|
|
49
|
-
core.map((ref) =>
|
|
50
|
-
|
|
51
|
-
scopedRef
|
|
52
|
-
acquire
|
|
53
|
-
|
|
59
|
+
core.map((ref) => {
|
|
60
|
+
const resource = Object.create(proto)
|
|
61
|
+
resource.scopedRef = ref
|
|
62
|
+
resource.acquire = core.provideContext(acquire, env)
|
|
63
|
+
return resource
|
|
64
|
+
})
|
|
54
65
|
))
|
|
55
66
|
|
|
56
67
|
/** @internal */
|
|
@@ -2,11 +2,11 @@ import * as Context from "../Context.js"
|
|
|
2
2
|
import type * as Effect from "../Effect.js"
|
|
3
3
|
import type { LazyArg } from "../Function.js"
|
|
4
4
|
import { dual, pipe } from "../Function.js"
|
|
5
|
-
import { pipeArguments } from "../Pipeable.js"
|
|
6
5
|
import type * as Scope from "../Scope.js"
|
|
7
6
|
import type * as ScopedRef from "../ScopedRef.js"
|
|
8
7
|
import * as core from "./core.js"
|
|
9
8
|
import * as circular from "./effect/circular.js"
|
|
9
|
+
import * as effectable from "./effectable.js"
|
|
10
10
|
import * as fiberRuntime from "./fiberRuntime.js"
|
|
11
11
|
import * as ref from "./ref.js"
|
|
12
12
|
import * as synchronized from "./synchronizedRef.js"
|
|
@@ -25,6 +25,15 @@ const scopedRefVariance = {
|
|
|
25
25
|
_A: (_: any) => _
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/** @internal */
|
|
29
|
+
const proto: ThisType<ScopedRef.ScopedRef<any>> = {
|
|
30
|
+
...effectable.CommitPrototype,
|
|
31
|
+
commit() {
|
|
32
|
+
return get(this)
|
|
33
|
+
},
|
|
34
|
+
[ScopedRefTypeId]: scopedRefVariance
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
/** @internal */
|
|
29
38
|
const close = <A>(self: ScopedRef.ScopedRef<A>): Effect.Effect<void> =>
|
|
30
39
|
core.flatMap(ref.get(self.ref), (tuple) => tuple[0].close(core.exitVoid))
|
|
@@ -41,13 +50,8 @@ export const fromAcquire = <A, E, R>(
|
|
|
41
50
|
core.flatMap((value) =>
|
|
42
51
|
circular.makeSynchronized([newScope, value] as const).pipe(
|
|
43
52
|
core.flatMap((ref) => {
|
|
44
|
-
const scopedRef
|
|
45
|
-
|
|
46
|
-
pipe() {
|
|
47
|
-
return pipeArguments(this, arguments)
|
|
48
|
-
},
|
|
49
|
-
ref
|
|
50
|
-
}
|
|
53
|
+
const scopedRef = Object.create(proto)
|
|
54
|
+
scopedRef.ref = ref
|
|
51
55
|
return pipe(
|
|
52
56
|
fiberRuntime.addFinalizer(() => close(scopedRef)),
|
|
53
57
|
core.as(scopedRef)
|
package/src/internal/stm/core.ts
CHANGED
|
@@ -56,7 +56,7 @@ export type Primitive =
|
|
|
56
56
|
|
|
57
57
|
/** @internal */
|
|
58
58
|
type Op<Tag extends string, Body = {}> = STM.STM<never> & Body & {
|
|
59
|
-
readonly
|
|
59
|
+
readonly _op: OP_COMMIT
|
|
60
60
|
readonly effect_instruction_i0: Tag
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -150,7 +150,6 @@ const stmVariance = {
|
|
|
150
150
|
|
|
151
151
|
/** @internal */
|
|
152
152
|
class STMPrimitive implements STM.STM<any, any, any> {
|
|
153
|
-
public _tag = OP_COMMIT
|
|
154
153
|
public _op = OP_COMMIT
|
|
155
154
|
public effect_instruction_i1: any = undefined
|
|
156
155
|
public effect_instruction_i2: any = undefined;
|
|
@@ -481,7 +480,7 @@ export class STMDriver<in out R, out E, out A> {
|
|
|
481
480
|
try {
|
|
482
481
|
const current = curr
|
|
483
482
|
if (current) {
|
|
484
|
-
switch (current.
|
|
483
|
+
switch (current._op) {
|
|
485
484
|
case "Tag": {
|
|
486
485
|
curr = effect((_, __, env) => Context.unsafeGet(env, current)) as Primitive
|
|
487
486
|
break
|
package/src/internal/version.ts
CHANGED