effect 2.4.5 → 2.4.7
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/Channel.js +10 -2
- package/dist/cjs/Channel.js.map +1 -1
- package/dist/cjs/Effect.js +26 -4
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/FiberMap.js +3 -0
- package/dist/cjs/FiberMap.js.map +1 -1
- package/dist/cjs/FiberSet.js +4 -0
- package/dist/cjs/FiberSet.js.map +1 -1
- package/dist/cjs/internal/cause.js +2 -2
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/channel.js +75 -1
- package/dist/cjs/internal/channel.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +0 -2
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/core.js +148 -126
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +29 -29
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/layer.js +2 -2
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/runtime.js +4 -6
- package/dist/cjs/internal/runtime.js.map +1 -1
- package/dist/cjs/internal/stm/core.js +36 -36
- package/dist/cjs/internal/stm/core.js.map +1 -1
- package/dist/cjs/internal/stream.js +2 -73
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Channel.d.ts +8 -0
- package/dist/dts/Channel.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +38 -2
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/FiberMap.d.ts.map +1 -1
- package/dist/dts/FiberSet.d.ts.map +1 -1
- package/dist/esm/Channel.js +8 -0
- package/dist/esm/Channel.js.map +1 -1
- package/dist/esm/Effect.js +22 -0
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/FiberMap.js +3 -0
- package/dist/esm/FiberMap.js.map +1 -1
- package/dist/esm/FiberSet.js +4 -0
- package/dist/esm/FiberSet.js.map +1 -1
- package/dist/esm/internal/cause.js +2 -2
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/channel.js +73 -0
- package/dist/esm/internal/channel.js.map +1 -1
- package/dist/esm/internal/core-effect.js +0 -2
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/core.js +144 -123
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +29 -29
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/layer.js +2 -2
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/runtime.js +4 -6
- package/dist/esm/internal/runtime.js.map +1 -1
- package/dist/esm/internal/stm/core.js +36 -36
- package/dist/esm/internal/stm/core.js.map +1 -1
- package/dist/esm/internal/stream.js +2 -73
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Channel.ts +17 -0
- package/src/Effect.ts +45 -2
- package/src/Exit.ts +2 -2
- package/src/FiberMap.ts +4 -0
- package/src/FiberSet.ts +4 -0
- package/src/internal/cause.ts +2 -2
- package/src/internal/channel.ts +92 -0
- package/src/internal/core-effect.ts +0 -2
- package/src/internal/core.ts +167 -134
- package/src/internal/fiberRuntime.ts +30 -30
- package/src/internal/layer.ts +4 -4
- package/src/internal/runtime.ts +4 -6
- package/src/internal/stm/core.ts +49 -49
- package/src/internal/stream.ts +2 -82
- package/src/internal/version.ts +1 -1
- package/dist/cjs/internal/internalize.js +0 -15
- package/dist/cjs/internal/internalize.js.map +0 -1
- package/dist/dts/internal/internalize.d.ts +0 -2
- package/dist/dts/internal/internalize.d.ts.map +0 -1
- package/dist/esm/internal/internalize.js +0 -8
- package/dist/esm/internal/internalize.js.map +0 -1
- package/src/internal/internalize.ts +0 -5
|
@@ -143,7 +143,7 @@ const contOpSuccess = {
|
|
|
143
143
|
cont: core.OnSuccess,
|
|
144
144
|
value: unknown
|
|
145
145
|
) => {
|
|
146
|
-
return cont.
|
|
146
|
+
return cont.effect_instruction_i1(value)
|
|
147
147
|
},
|
|
148
148
|
["OnStep"]: (
|
|
149
149
|
_: FiberRuntime<any, any>,
|
|
@@ -157,7 +157,7 @@ const contOpSuccess = {
|
|
|
157
157
|
cont: core.OnSuccessAndFailure,
|
|
158
158
|
value: unknown
|
|
159
159
|
) => {
|
|
160
|
-
return cont.
|
|
160
|
+
return cont.effect_instruction_i2(value)
|
|
161
161
|
},
|
|
162
162
|
[OpCodes.OP_REVERT_FLAGS]: (
|
|
163
163
|
self: FiberRuntime<any, any>,
|
|
@@ -176,10 +176,10 @@ const contOpSuccess = {
|
|
|
176
176
|
cont: core.While,
|
|
177
177
|
value: unknown
|
|
178
178
|
) => {
|
|
179
|
-
cont.
|
|
180
|
-
if (cont.
|
|
179
|
+
cont.effect_instruction_i2(value)
|
|
180
|
+
if (cont.effect_instruction_i0()) {
|
|
181
181
|
self.pushStack(cont)
|
|
182
|
-
return cont.
|
|
182
|
+
return cont.effect_instruction_i1()
|
|
183
183
|
} else {
|
|
184
184
|
return core.unit
|
|
185
185
|
}
|
|
@@ -1066,7 +1066,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
|
|
|
1066
1066
|
}
|
|
1067
1067
|
|
|
1068
1068
|
[OpCodes.OP_SYNC](op: core.Primitive & { _op: OpCodes.OP_SYNC }) {
|
|
1069
|
-
const value = op.
|
|
1069
|
+
const value = op.effect_instruction_i0()
|
|
1070
1070
|
const cont = this.getNextSuccessCont()
|
|
1071
1071
|
if (cont !== undefined) {
|
|
1072
1072
|
if (!(cont._op in contOpSuccess)) {
|
|
@@ -1090,7 +1090,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
|
|
|
1090
1090
|
absurd(cont)
|
|
1091
1091
|
}
|
|
1092
1092
|
// @ts-expect-error
|
|
1093
|
-
return contOpSuccess[cont._op](this, cont, oldCur.
|
|
1093
|
+
return contOpSuccess[cont._op](this, cont, oldCur.effect_instruction_i0)
|
|
1094
1094
|
} else {
|
|
1095
1095
|
yieldedOpChannel.currentOp = oldCur
|
|
1096
1096
|
return YieldedOp
|
|
@@ -1098,14 +1098,14 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
|
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
1100
|
[OpCodes.OP_FAILURE](op: core.Primitive & { _op: OpCodes.OP_FAILURE }) {
|
|
1101
|
-
const cause = op.
|
|
1101
|
+
const cause = op.effect_instruction_i0
|
|
1102
1102
|
const cont = this.getNextFailCont()
|
|
1103
1103
|
if (cont !== undefined) {
|
|
1104
1104
|
switch (cont._op) {
|
|
1105
1105
|
case OpCodes.OP_ON_FAILURE:
|
|
1106
1106
|
case OpCodes.OP_ON_SUCCESS_AND_FAILURE: {
|
|
1107
1107
|
if (!(_runtimeFlags.interruptible(this._runtimeFlags) && this.isInterrupted())) {
|
|
1108
|
-
return cont.
|
|
1108
|
+
return cont.effect_instruction_i1(cause)
|
|
1109
1109
|
} else {
|
|
1110
1110
|
return core.exitFailCause(internalCause.stripFailures(cause))
|
|
1111
1111
|
}
|
|
@@ -1136,7 +1136,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
|
|
|
1136
1136
|
}
|
|
1137
1137
|
|
|
1138
1138
|
[OpCodes.OP_WITH_RUNTIME](op: core.Primitive & { _op: OpCodes.OP_WITH_RUNTIME }) {
|
|
1139
|
-
return op.
|
|
1139
|
+
return op.effect_instruction_i0(
|
|
1140
1140
|
this as FiberRuntime<unknown, unknown>,
|
|
1141
1141
|
FiberStatus.running(this._runtimeFlags) as FiberStatus.Running
|
|
1142
1142
|
)
|
|
@@ -1158,7 +1158,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
|
|
|
1158
1158
|
const patchRefs = FiberRefsPatch.diff(snap.refs, refs)
|
|
1159
1159
|
const patchFlags = _runtimeFlags.diff(snap.flags, flags)
|
|
1160
1160
|
return core.exitSucceed(core.blocked(
|
|
1161
|
-
op.
|
|
1161
|
+
op.effect_instruction_i0,
|
|
1162
1162
|
core.withFiberRuntime<unknown, unknown>((newFiber) => {
|
|
1163
1163
|
while (frames.length > 0) {
|
|
1164
1164
|
newFiber.pushStack(frames.pop()!)
|
|
@@ -1167,24 +1167,24 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
|
|
|
1167
1167
|
FiberRefsPatch.patch(newFiber.id(), newFiber.getFiberRefs())(patchRefs)
|
|
1168
1168
|
)
|
|
1169
1169
|
newFiber._runtimeFlags = _runtimeFlags.patch(patchFlags)(newFiber._runtimeFlags)
|
|
1170
|
-
return op.
|
|
1170
|
+
return op.effect_instruction_i1
|
|
1171
1171
|
})
|
|
1172
1172
|
))
|
|
1173
1173
|
}
|
|
1174
1174
|
return core.uninterruptibleMask((restore) =>
|
|
1175
1175
|
core.flatMap(
|
|
1176
|
-
forkDaemon(core.runRequestBlock(op.
|
|
1177
|
-
() => restore(op.
|
|
1176
|
+
forkDaemon(core.runRequestBlock(op.effect_instruction_i0)),
|
|
1177
|
+
() => restore(op.effect_instruction_i1)
|
|
1178
1178
|
)
|
|
1179
1179
|
)
|
|
1180
1180
|
}
|
|
1181
1181
|
|
|
1182
1182
|
["RunBlocked"](op: core.Primitive & { _op: "RunBlocked" }) {
|
|
1183
|
-
return runBlockedRequests(op.
|
|
1183
|
+
return runBlockedRequests(op.effect_instruction_i0)
|
|
1184
1184
|
}
|
|
1185
1185
|
|
|
1186
1186
|
[OpCodes.OP_UPDATE_RUNTIME_FLAGS](op: core.Primitive & { _op: OpCodes.OP_UPDATE_RUNTIME_FLAGS }) {
|
|
1187
|
-
const updateFlags = op.
|
|
1187
|
+
const updateFlags = op.effect_instruction_i0
|
|
1188
1188
|
const oldRuntimeFlags = this._runtimeFlags
|
|
1189
1189
|
const newRuntimeFlags = _runtimeFlags.patch(oldRuntimeFlags, updateFlags)
|
|
1190
1190
|
// One more chance to short circuit: if we're immediately going
|
|
@@ -1196,11 +1196,11 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
|
|
|
1196
1196
|
} else {
|
|
1197
1197
|
// Impossible to short circuit, so record the changes
|
|
1198
1198
|
this.patchRuntimeFlags(this._runtimeFlags, updateFlags)
|
|
1199
|
-
if (op.
|
|
1199
|
+
if (op.effect_instruction_i1) {
|
|
1200
1200
|
// Since we updated the flags, we need to revert them
|
|
1201
1201
|
const revertFlags = _runtimeFlags.diff(newRuntimeFlags, oldRuntimeFlags)
|
|
1202
1202
|
this.pushStack(new core.RevertFlags(revertFlags, op))
|
|
1203
|
-
return op.
|
|
1203
|
+
return op.effect_instruction_i1(oldRuntimeFlags)
|
|
1204
1204
|
} else {
|
|
1205
1205
|
return core.exitUnit
|
|
1206
1206
|
}
|
|
@@ -1209,27 +1209,27 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
|
|
|
1209
1209
|
|
|
1210
1210
|
[OpCodes.OP_ON_SUCCESS](op: core.Primitive & { _op: OpCodes.OP_ON_SUCCESS }) {
|
|
1211
1211
|
this.pushStack(op)
|
|
1212
|
-
return op.
|
|
1212
|
+
return op.effect_instruction_i0
|
|
1213
1213
|
}
|
|
1214
1214
|
|
|
1215
1215
|
["OnStep"](op: core.Primitive & { _op: "OnStep" }) {
|
|
1216
1216
|
this.pushStack(op)
|
|
1217
|
-
return op.
|
|
1217
|
+
return op.effect_instruction_i0
|
|
1218
1218
|
}
|
|
1219
1219
|
|
|
1220
1220
|
[OpCodes.OP_ON_FAILURE](op: core.Primitive & { _op: OpCodes.OP_ON_FAILURE }) {
|
|
1221
1221
|
this.pushStack(op)
|
|
1222
|
-
return op.
|
|
1222
|
+
return op.effect_instruction_i0
|
|
1223
1223
|
}
|
|
1224
1224
|
|
|
1225
1225
|
[OpCodes.OP_ON_SUCCESS_AND_FAILURE](op: core.Primitive & { _op: OpCodes.OP_ON_SUCCESS_AND_FAILURE }) {
|
|
1226
1226
|
this.pushStack(op)
|
|
1227
|
-
return op.
|
|
1227
|
+
return op.effect_instruction_i0
|
|
1228
1228
|
}
|
|
1229
1229
|
|
|
1230
1230
|
[OpCodes.OP_ASYNC](op: core.Primitive & { _op: OpCodes.OP_ASYNC }) {
|
|
1231
|
-
this._asyncBlockingOn = op.
|
|
1232
|
-
this.initiateAsync(this._runtimeFlags, op.
|
|
1231
|
+
this._asyncBlockingOn = op.effect_instruction_i1
|
|
1232
|
+
this.initiateAsync(this._runtimeFlags, op.effect_instruction_i0)
|
|
1233
1233
|
yieldedOpChannel.currentOp = op
|
|
1234
1234
|
return YieldedOp
|
|
1235
1235
|
}
|
|
@@ -1241,8 +1241,8 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
|
|
|
1241
1241
|
}
|
|
1242
1242
|
|
|
1243
1243
|
[OpCodes.OP_WHILE](op: core.Primitive & { _op: OpCodes.OP_WHILE }) {
|
|
1244
|
-
const check = op.
|
|
1245
|
-
const body = op.
|
|
1244
|
+
const check = op.effect_instruction_i0
|
|
1245
|
+
const body = op.effect_instruction_i1
|
|
1246
1246
|
if (check()) {
|
|
1247
1247
|
this.pushStack(op)
|
|
1248
1248
|
return body()
|
|
@@ -1833,7 +1833,7 @@ export const allSuccesses = <A, E, R>(
|
|
|
1833
1833
|
): Effect.Effect<Array<A>, never, R> =>
|
|
1834
1834
|
core.map(
|
|
1835
1835
|
all(RA.fromIterable(elements).map(core.exit), options),
|
|
1836
|
-
RA.filterMap((exit) => core.exitIsSuccess(exit) ? Option.some(exit.
|
|
1836
|
+
RA.filterMap((exit) => core.exitIsSuccess(exit) ? Option.some(exit.effect_instruction_i0) : Option.none())
|
|
1837
1837
|
)
|
|
1838
1838
|
|
|
1839
1839
|
/* @internal */
|
|
@@ -2099,7 +2099,7 @@ export const forEachConcurrentDiscard = <A, X, E, R>(
|
|
|
2099
2099
|
if (wrapped._op === "Failure") {
|
|
2100
2100
|
exit = wrapped
|
|
2101
2101
|
} else {
|
|
2102
|
-
exit = wrapped.
|
|
2102
|
+
exit = wrapped.effect_instruction_i0 as any
|
|
2103
2103
|
}
|
|
2104
2104
|
joinOrder.push(fiber)
|
|
2105
2105
|
fibers.delete(fiber)
|
|
@@ -2110,7 +2110,7 @@ export const forEachConcurrentDiscard = <A, X, E, R>(
|
|
|
2110
2110
|
() => core.exitUnit
|
|
2111
2111
|
)))
|
|
2112
2112
|
} else if (residual.length + results.length === target) {
|
|
2113
|
-
const requests = residual.map((blocked) => blocked.
|
|
2113
|
+
const requests = residual.map((blocked) => blocked.effect_instruction_i0).reduce(_RequestBlock.par)
|
|
2114
2114
|
resume(core.succeed(core.blocked(
|
|
2115
2115
|
requests,
|
|
2116
2116
|
forEachConcurrentDiscard(
|
|
@@ -2119,7 +2119,7 @@ export const forEachConcurrentDiscard = <A, X, E, R>(
|
|
|
2119
2119
|
core.exitCollectAll(collectExits(), { parallel: true }),
|
|
2120
2120
|
() => core.exitUnit
|
|
2121
2121
|
),
|
|
2122
|
-
...residual.map((blocked) => blocked.
|
|
2122
|
+
...residual.map((blocked) => blocked.effect_instruction_i1)
|
|
2123
2123
|
],
|
|
2124
2124
|
(i) => i,
|
|
2125
2125
|
batching,
|
package/src/internal/layer.ts
CHANGED
|
@@ -232,9 +232,9 @@ class MemoMapImpl implements Layer.MemoMap {
|
|
|
232
232
|
switch (exit._tag) {
|
|
233
233
|
case EffectOpCodes.OP_FAILURE: {
|
|
234
234
|
return pipe(
|
|
235
|
-
core.deferredFailCause(deferred, exit.
|
|
235
|
+
core.deferredFailCause(deferred, exit.effect_instruction_i0),
|
|
236
236
|
core.zipRight(core.scopeClose(innerScope, exit)),
|
|
237
|
-
core.zipRight(core.failCause(exit.
|
|
237
|
+
core.zipRight(core.failCause(exit.effect_instruction_i0))
|
|
238
238
|
)
|
|
239
239
|
}
|
|
240
240
|
case EffectOpCodes.OP_SUCCESS: {
|
|
@@ -256,8 +256,8 @@ class MemoMapImpl implements Layer.MemoMap {
|
|
|
256
256
|
core.flatMap((finalizer) => finalizer(exit))
|
|
257
257
|
))
|
|
258
258
|
),
|
|
259
|
-
core.zipRight(core.deferredSucceed(deferred, exit.
|
|
260
|
-
core.as(exit.
|
|
259
|
+
core.zipRight(core.deferredSucceed(deferred, exit.effect_instruction_i0)),
|
|
260
|
+
core.as(exit.effect_instruction_i0[1])
|
|
261
261
|
)
|
|
262
262
|
}
|
|
263
263
|
}
|
package/src/internal/runtime.ts
CHANGED
|
@@ -22,7 +22,6 @@ import * as core from "./core.js"
|
|
|
22
22
|
import * as executionStrategy from "./executionStrategy.js"
|
|
23
23
|
import * as FiberRuntime from "./fiberRuntime.js"
|
|
24
24
|
import * as fiberScope from "./fiberScope.js"
|
|
25
|
-
import { internalize } from "./internalize.js"
|
|
26
25
|
import * as OpCodes from "./opCodes/effect.js"
|
|
27
26
|
import * as runtimeFlags from "./runtimeFlags.js"
|
|
28
27
|
import * as _supervisor from "./supervisor.js"
|
|
@@ -126,9 +125,9 @@ export const unsafeRunCallback = <R>(runtime: Runtime.Runtime<R>) =>
|
|
|
126
125
|
export const unsafeRunSync = <R>(runtime: Runtime.Runtime<R>) => <A, E>(effect: Effect.Effect<A, E, R>): A => {
|
|
127
126
|
const result = unsafeRunSyncExit(runtime)(effect)
|
|
128
127
|
if (result._tag === "Failure") {
|
|
129
|
-
throw fiberFailure(result.
|
|
128
|
+
throw fiberFailure(result.effect_instruction_i0)
|
|
130
129
|
} else {
|
|
131
|
-
return result.
|
|
130
|
+
return result.effect_instruction_i0
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
133
|
|
|
@@ -267,10 +266,10 @@ export const unsafeRunPromise = <R>(runtime: Runtime.Runtime<R>) =>
|
|
|
267
266
|
unsafeRunPromiseExit(runtime)(effect, options).then((result) => {
|
|
268
267
|
switch (result._tag) {
|
|
269
268
|
case OpCodes.OP_SUCCESS: {
|
|
270
|
-
return result.
|
|
269
|
+
return result.effect_instruction_i0
|
|
271
270
|
}
|
|
272
271
|
case OpCodes.OP_FAILURE: {
|
|
273
|
-
throw fiberFailure(result.
|
|
272
|
+
throw fiberFailure(result.effect_instruction_i0)
|
|
274
273
|
}
|
|
275
274
|
}
|
|
276
275
|
})
|
|
@@ -477,7 +476,6 @@ export const asyncEffect = <A, E, R, R3, E2, R2>(
|
|
|
477
476
|
) => Effect.Effect<Effect.Effect<void, never, R3> | void, E2, R2>
|
|
478
477
|
): Effect.Effect<A, E | E2, R | R2 | R3> =>
|
|
479
478
|
core.suspend(() => {
|
|
480
|
-
internalize(register)
|
|
481
479
|
let cleanup: Effect.Effect<void, never, R3> | void = undefined
|
|
482
480
|
return core.flatMap(
|
|
483
481
|
core.deferredMake<A, E | E2>(),
|
package/src/internal/stm/core.ts
CHANGED
|
@@ -54,13 +54,13 @@ export type Primitive =
|
|
|
54
54
|
/** @internal */
|
|
55
55
|
type Op<Tag extends string, Body = {}> = STM.STM<never> & Body & {
|
|
56
56
|
readonly _tag: OP_COMMIT
|
|
57
|
-
readonly
|
|
57
|
+
readonly effect_instruction_i0: Tag
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/** @internal */
|
|
61
61
|
interface STMEffect extends
|
|
62
62
|
Op<OpCodes.OP_WITH_STM_RUNTIME, {
|
|
63
|
-
readonly
|
|
63
|
+
readonly effect_instruction_i1: (
|
|
64
64
|
runtime: STMDriver<unknown, unknown, unknown>
|
|
65
65
|
) => STM.STM<unknown, unknown, unknown>
|
|
66
66
|
}>
|
|
@@ -69,46 +69,46 @@ interface STMEffect extends
|
|
|
69
69
|
/** @internal */
|
|
70
70
|
interface STMOnFailure extends
|
|
71
71
|
Op<OpCodes.OP_ON_FAILURE, {
|
|
72
|
-
readonly
|
|
73
|
-
readonly
|
|
72
|
+
readonly effect_instruction_i1: STM.STM<unknown, unknown, unknown>
|
|
73
|
+
readonly effect_instruction_i2: (error: unknown) => STM.STM<unknown, unknown, unknown>
|
|
74
74
|
}>
|
|
75
75
|
{}
|
|
76
76
|
|
|
77
77
|
/** @internal */
|
|
78
78
|
interface STMOnRetry extends
|
|
79
79
|
Op<OpCodes.OP_ON_RETRY, {
|
|
80
|
-
readonly
|
|
81
|
-
readonly
|
|
80
|
+
readonly effect_instruction_i1: STM.STM<unknown, unknown, unknown>
|
|
81
|
+
readonly effect_instruction_i2: () => STM.STM<unknown, unknown, unknown>
|
|
82
82
|
}>
|
|
83
83
|
{}
|
|
84
84
|
|
|
85
85
|
/** @internal */
|
|
86
86
|
interface STMOnSuccess extends
|
|
87
87
|
Op<OpCodes.OP_ON_SUCCESS, {
|
|
88
|
-
readonly
|
|
89
|
-
readonly
|
|
88
|
+
readonly effect_instruction_i1: STM.STM<unknown, unknown, unknown>
|
|
89
|
+
readonly effect_instruction_i2: (a: unknown) => STM.STM<unknown, unknown, unknown>
|
|
90
90
|
}>
|
|
91
91
|
{}
|
|
92
92
|
|
|
93
93
|
/** @internal */
|
|
94
94
|
interface STMProvide extends
|
|
95
95
|
Op<OpCodes.OP_PROVIDE, {
|
|
96
|
-
readonly
|
|
97
|
-
readonly
|
|
96
|
+
readonly effect_instruction_i1: STM.STM<unknown, unknown, unknown>
|
|
97
|
+
readonly effect_instruction_i2: (context: Context.Context<unknown>) => Context.Context<unknown>
|
|
98
98
|
}>
|
|
99
99
|
{}
|
|
100
100
|
|
|
101
101
|
/** @internal */
|
|
102
102
|
interface STMSync extends
|
|
103
103
|
Op<OpCodes.OP_SYNC, {
|
|
104
|
-
readonly
|
|
104
|
+
readonly effect_instruction_i1: () => unknown
|
|
105
105
|
}>
|
|
106
106
|
{}
|
|
107
107
|
|
|
108
108
|
/** @internal */
|
|
109
109
|
interface STMSucceed extends
|
|
110
110
|
Op<OpCodes.OP_SUCCEED, {
|
|
111
|
-
readonly
|
|
111
|
+
readonly effect_instruction_i1: unknown
|
|
112
112
|
}>
|
|
113
113
|
{}
|
|
114
114
|
|
|
@@ -118,21 +118,21 @@ interface STMRetry extends Op<OpCodes.OP_RETRY, {}> {}
|
|
|
118
118
|
/** @internal */
|
|
119
119
|
interface STMFail extends
|
|
120
120
|
Op<OpCodes.OP_FAIL, {
|
|
121
|
-
readonly
|
|
121
|
+
readonly effect_instruction_i1: LazyArg<unknown>
|
|
122
122
|
}>
|
|
123
123
|
{}
|
|
124
124
|
|
|
125
125
|
/** @internal */
|
|
126
126
|
interface STMDie extends
|
|
127
127
|
Op<OpCodes.OP_DIE, {
|
|
128
|
-
readonly
|
|
128
|
+
readonly effect_instruction_i1: LazyArg<unknown>
|
|
129
129
|
}>
|
|
130
130
|
{}
|
|
131
131
|
|
|
132
132
|
/** @internal */
|
|
133
133
|
interface STMInterrupt extends
|
|
134
134
|
Op<OpCodes.OP_INTERRUPT, {
|
|
135
|
-
readonly
|
|
135
|
+
readonly effect_instruction_i1: FiberId.Runtime
|
|
136
136
|
}>
|
|
137
137
|
{}
|
|
138
138
|
|
|
@@ -149,8 +149,8 @@ const stmVariance = {
|
|
|
149
149
|
class STMPrimitive implements STM.STM<any, any, any> {
|
|
150
150
|
public _tag = OP_COMMIT
|
|
151
151
|
public _op = OP_COMMIT
|
|
152
|
-
public
|
|
153
|
-
public
|
|
152
|
+
public effect_instruction_i1: any = undefined
|
|
153
|
+
public effect_instruction_i2: any = undefined;
|
|
154
154
|
[Effect.EffectTypeId]: any;
|
|
155
155
|
[StreamTypeId]: any;
|
|
156
156
|
[SinkTypeId]: any;
|
|
@@ -158,7 +158,7 @@ class STMPrimitive implements STM.STM<any, any, any> {
|
|
|
158
158
|
get [STMTypeId]() {
|
|
159
159
|
return stmVariance
|
|
160
160
|
}
|
|
161
|
-
constructor(readonly
|
|
161
|
+
constructor(readonly effect_instruction_i0: Primitive["effect_instruction_i0"]) {
|
|
162
162
|
this[Effect.EffectTypeId] = effectVariance
|
|
163
163
|
this[StreamTypeId] = stmVariance
|
|
164
164
|
this[SinkTypeId] = stmVariance
|
|
@@ -446,7 +446,7 @@ export class STMDriver<in out R, out E, out A> {
|
|
|
446
446
|
|
|
447
447
|
nextSuccess() {
|
|
448
448
|
let current = this.popStack()
|
|
449
|
-
while (current !== undefined && current.
|
|
449
|
+
while (current !== undefined && current.effect_instruction_i0 !== OpCodes.OP_ON_SUCCESS) {
|
|
450
450
|
current = this.popStack()
|
|
451
451
|
}
|
|
452
452
|
return current
|
|
@@ -454,7 +454,7 @@ export class STMDriver<in out R, out E, out A> {
|
|
|
454
454
|
|
|
455
455
|
nextFailure() {
|
|
456
456
|
let current = this.popStack()
|
|
457
|
-
while (current !== undefined && current.
|
|
457
|
+
while (current !== undefined && current.effect_instruction_i0 !== OpCodes.OP_ON_FAILURE) {
|
|
458
458
|
current = this.popStack()
|
|
459
459
|
}
|
|
460
460
|
return current
|
|
@@ -462,7 +462,7 @@ export class STMDriver<in out R, out E, out A> {
|
|
|
462
462
|
|
|
463
463
|
nextRetry() {
|
|
464
464
|
let current = this.popStack()
|
|
465
|
-
while (current !== undefined && current.
|
|
465
|
+
while (current !== undefined && current.effect_instruction_i0 !== OpCodes.OP_ON_RETRY) {
|
|
466
466
|
current = this.popStack()
|
|
467
467
|
}
|
|
468
468
|
return current
|
|
@@ -497,17 +497,17 @@ export class STMDriver<in out R, out E, out A> {
|
|
|
497
497
|
break
|
|
498
498
|
}
|
|
499
499
|
case "Commit": {
|
|
500
|
-
switch (current.
|
|
500
|
+
switch (current.effect_instruction_i0) {
|
|
501
501
|
case OpCodes.OP_DIE: {
|
|
502
|
-
exit = TExit.die(current.
|
|
502
|
+
exit = TExit.die(current.effect_instruction_i1())
|
|
503
503
|
break
|
|
504
504
|
}
|
|
505
505
|
case OpCodes.OP_FAIL: {
|
|
506
506
|
const cont = this.nextFailure()
|
|
507
507
|
if (cont === undefined) {
|
|
508
|
-
exit = TExit.fail(current.
|
|
508
|
+
exit = TExit.fail(current.effect_instruction_i1())
|
|
509
509
|
} else {
|
|
510
|
-
curr = cont.
|
|
510
|
+
curr = cont.effect_instruction_i2(current.effect_instruction_i1()) as Primitive
|
|
511
511
|
}
|
|
512
512
|
break
|
|
513
513
|
}
|
|
@@ -516,7 +516,7 @@ export class STMDriver<in out R, out E, out A> {
|
|
|
516
516
|
if (cont === undefined) {
|
|
517
517
|
exit = TExit.retry
|
|
518
518
|
} else {
|
|
519
|
-
curr = cont.
|
|
519
|
+
curr = cont.effect_instruction_i2() as Primitive
|
|
520
520
|
}
|
|
521
521
|
break
|
|
522
522
|
}
|
|
@@ -525,42 +525,42 @@ export class STMDriver<in out R, out E, out A> {
|
|
|
525
525
|
break
|
|
526
526
|
}
|
|
527
527
|
case OpCodes.OP_WITH_STM_RUNTIME: {
|
|
528
|
-
curr = current.
|
|
528
|
+
curr = current.effect_instruction_i1(this as STMDriver<unknown, unknown, unknown>) as Primitive
|
|
529
529
|
break
|
|
530
530
|
}
|
|
531
531
|
case OpCodes.OP_ON_SUCCESS:
|
|
532
532
|
case OpCodes.OP_ON_FAILURE:
|
|
533
533
|
case OpCodes.OP_ON_RETRY: {
|
|
534
534
|
this.pushStack(current)
|
|
535
|
-
curr = current.
|
|
535
|
+
curr = current.effect_instruction_i1 as Primitive
|
|
536
536
|
break
|
|
537
537
|
}
|
|
538
538
|
case OpCodes.OP_PROVIDE: {
|
|
539
539
|
const env = this.env
|
|
540
|
-
this.env = current.
|
|
540
|
+
this.env = current.effect_instruction_i2(env)
|
|
541
541
|
curr = pipe(
|
|
542
|
-
current.
|
|
542
|
+
current.effect_instruction_i1,
|
|
543
543
|
ensuring(sync(() => (this.env = env)))
|
|
544
544
|
) as Primitive
|
|
545
545
|
break
|
|
546
546
|
}
|
|
547
547
|
case OpCodes.OP_SUCCEED: {
|
|
548
|
-
const value = current.
|
|
548
|
+
const value = current.effect_instruction_i1
|
|
549
549
|
const cont = this.nextSuccess()
|
|
550
550
|
if (cont === undefined) {
|
|
551
551
|
exit = TExit.succeed(value)
|
|
552
552
|
} else {
|
|
553
|
-
curr = cont.
|
|
553
|
+
curr = cont.effect_instruction_i2(value) as Primitive
|
|
554
554
|
}
|
|
555
555
|
break
|
|
556
556
|
}
|
|
557
557
|
case OpCodes.OP_SYNC: {
|
|
558
|
-
const value = current.
|
|
558
|
+
const value = current.effect_instruction_i1()
|
|
559
559
|
const cont = this.nextSuccess()
|
|
560
560
|
if (cont === undefined) {
|
|
561
561
|
exit = TExit.succeed(value)
|
|
562
562
|
} else {
|
|
563
|
-
curr = cont.
|
|
563
|
+
curr = cont.effect_instruction_i2(value) as Primitive
|
|
564
564
|
}
|
|
565
565
|
break
|
|
566
566
|
}
|
|
@@ -590,8 +590,8 @@ export const catchAll = dual<
|
|
|
590
590
|
) => STM.STM<B | A, E1, R1 | R>
|
|
591
591
|
>(2, (self, f) => {
|
|
592
592
|
const stm = new STMPrimitive(OpCodes.OP_ON_FAILURE)
|
|
593
|
-
stm.
|
|
594
|
-
stm.
|
|
593
|
+
stm.effect_instruction_i1 = self
|
|
594
|
+
stm.effect_instruction_i2 = f
|
|
595
595
|
return stm
|
|
596
596
|
})
|
|
597
597
|
|
|
@@ -608,8 +608,8 @@ export const mapInputContext = dual<
|
|
|
608
608
|
) => STM.STM<A, E, R0>
|
|
609
609
|
>(2, (self, f) => {
|
|
610
610
|
const stm = new STMPrimitive(OpCodes.OP_PROVIDE)
|
|
611
|
-
stm.
|
|
612
|
-
stm.
|
|
611
|
+
stm.effect_instruction_i1 = self
|
|
612
|
+
stm.effect_instruction_i2 = f
|
|
613
613
|
return stm
|
|
614
614
|
})
|
|
615
615
|
|
|
@@ -622,7 +622,7 @@ export const dieMessage = (message: string): STM.STM<never> => dieSync(() => new
|
|
|
622
622
|
/** @internal */
|
|
623
623
|
export const dieSync = (evaluate: LazyArg<unknown>): STM.STM<never> => {
|
|
624
624
|
const stm = new STMPrimitive(OpCodes.OP_DIE)
|
|
625
|
-
stm.
|
|
625
|
+
stm.effect_instruction_i1 = evaluate
|
|
626
626
|
return stm as any
|
|
627
627
|
}
|
|
628
628
|
|
|
@@ -647,7 +647,7 @@ export const fail = <E>(error: E): STM.STM<never, E> => failSync(() => error)
|
|
|
647
647
|
/** @internal */
|
|
648
648
|
export const failSync = <E>(evaluate: LazyArg<E>): STM.STM<never, E> => {
|
|
649
649
|
const stm = new STMPrimitive(OpCodes.OP_FAIL)
|
|
650
|
-
stm.
|
|
650
|
+
stm.effect_instruction_i1 = evaluate
|
|
651
651
|
return stm as any
|
|
652
652
|
}
|
|
653
653
|
|
|
@@ -657,8 +657,8 @@ export const flatMap = dual<
|
|
|
657
657
|
<A, E, R, A2, E1, R1>(self: STM.STM<A, E, R>, f: (a: A) => STM.STM<A2, E1, R1>) => STM.STM<A2, E1 | E, R1 | R>
|
|
658
658
|
>(2, (self, f) => {
|
|
659
659
|
const stm = new STMPrimitive(OpCodes.OP_ON_SUCCESS)
|
|
660
|
-
stm.
|
|
661
|
-
stm.
|
|
660
|
+
stm.effect_instruction_i1 = self
|
|
661
|
+
stm.effect_instruction_i2 = f
|
|
662
662
|
return stm
|
|
663
663
|
})
|
|
664
664
|
|
|
@@ -705,21 +705,21 @@ export const withSTMRuntime = <A, E = never, R = never>(
|
|
|
705
705
|
f: (runtime: STMDriver<unknown, unknown, unknown>) => STM.STM<A, E, R>
|
|
706
706
|
): STM.STM<A, E, R> => {
|
|
707
707
|
const stm = new STMPrimitive(OpCodes.OP_WITH_STM_RUNTIME)
|
|
708
|
-
stm.
|
|
708
|
+
stm.effect_instruction_i1 = f
|
|
709
709
|
return stm
|
|
710
710
|
}
|
|
711
711
|
|
|
712
712
|
/** @internal */
|
|
713
713
|
export const interrupt: STM.STM<never> = withSTMRuntime((_) => {
|
|
714
714
|
const stm = new STMPrimitive(OpCodes.OP_INTERRUPT)
|
|
715
|
-
stm.
|
|
715
|
+
stm.effect_instruction_i1 = _.fiberId
|
|
716
716
|
return stm as any
|
|
717
717
|
})
|
|
718
718
|
|
|
719
719
|
/** @internal */
|
|
720
720
|
export const interruptAs = (fiberId: FiberId.FiberId): STM.STM<never> => {
|
|
721
721
|
const stm = new STMPrimitive(OpCodes.OP_INTERRUPT)
|
|
722
|
-
stm.
|
|
722
|
+
stm.effect_instruction_i1 = fiberId
|
|
723
723
|
return stm as any
|
|
724
724
|
}
|
|
725
725
|
|
|
@@ -742,8 +742,8 @@ export const orTry = dual<
|
|
|
742
742
|
) => STM.STM<A1 | A, E1 | E, R1 | R>
|
|
743
743
|
>(2, (self, that) => {
|
|
744
744
|
const stm = new STMPrimitive(OpCodes.OP_ON_RETRY)
|
|
745
|
-
stm.
|
|
746
|
-
stm.
|
|
745
|
+
stm.effect_instruction_i1 = self
|
|
746
|
+
stm.effect_instruction_i2 = that
|
|
747
747
|
return stm
|
|
748
748
|
})
|
|
749
749
|
|
|
@@ -753,14 +753,14 @@ export const retry: STM.STM<never> = new STMPrimitive(OpCodes.OP_RETRY)
|
|
|
753
753
|
/** @internal */
|
|
754
754
|
export const succeed = <A>(value: A): STM.STM<A> => {
|
|
755
755
|
const stm = new STMPrimitive(OpCodes.OP_SUCCEED)
|
|
756
|
-
stm.
|
|
756
|
+
stm.effect_instruction_i1 = value
|
|
757
757
|
return stm as any
|
|
758
758
|
}
|
|
759
759
|
|
|
760
760
|
/** @internal */
|
|
761
761
|
export const sync = <A>(evaluate: () => A): STM.STM<A> => {
|
|
762
762
|
const stm = new STMPrimitive(OpCodes.OP_SYNC)
|
|
763
|
-
stm.
|
|
763
|
+
stm.effect_instruction_i1 = evaluate
|
|
764
764
|
return stm as any
|
|
765
765
|
}
|
|
766
766
|
|