effect 3.2.2 → 3.2.4

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.
Files changed (48) hide show
  1. package/dist/cjs/Array.js +777 -17
  2. package/dist/cjs/Array.js.map +1 -1
  3. package/dist/cjs/Utils.js +10 -13
  4. package/dist/cjs/Utils.js.map +1 -1
  5. package/dist/cjs/internal/cause.js +2 -4
  6. package/dist/cjs/internal/cause.js.map +1 -1
  7. package/dist/cjs/internal/core-effect.js +3 -3
  8. package/dist/cjs/internal/core-effect.js.map +1 -1
  9. package/dist/cjs/internal/core.js +4 -4
  10. package/dist/cjs/internal/core.js.map +1 -1
  11. package/dist/cjs/internal/fiberRuntime.js +10 -10
  12. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  13. package/dist/cjs/internal/pool.js +2 -2
  14. package/dist/cjs/internal/pool.js.map +1 -1
  15. package/dist/cjs/internal/stm/core.js +9 -9
  16. package/dist/cjs/internal/stm/core.js.map +1 -1
  17. package/dist/cjs/internal/version.js +1 -1
  18. package/dist/dts/Array.d.ts +776 -16
  19. package/dist/dts/Array.d.ts.map +1 -1
  20. package/dist/dts/Utils.d.ts +1 -7
  21. package/dist/dts/Utils.d.ts.map +1 -1
  22. package/dist/esm/Array.js +777 -17
  23. package/dist/esm/Array.js.map +1 -1
  24. package/dist/esm/Utils.js +9 -12
  25. package/dist/esm/Utils.js.map +1 -1
  26. package/dist/esm/internal/cause.js +2 -4
  27. package/dist/esm/internal/cause.js.map +1 -1
  28. package/dist/esm/internal/core-effect.js +4 -4
  29. package/dist/esm/internal/core-effect.js.map +1 -1
  30. package/dist/esm/internal/core.js +5 -5
  31. package/dist/esm/internal/core.js.map +1 -1
  32. package/dist/esm/internal/fiberRuntime.js +11 -11
  33. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  34. package/dist/esm/internal/pool.js +2 -2
  35. package/dist/esm/internal/pool.js.map +1 -1
  36. package/dist/esm/internal/stm/core.js +10 -10
  37. package/dist/esm/internal/stm/core.js.map +1 -1
  38. package/dist/esm/internal/version.js +1 -1
  39. package/package.json +1 -1
  40. package/src/Array.ts +777 -17
  41. package/src/Utils.ts +9 -11
  42. package/src/internal/cause.ts +2 -4
  43. package/src/internal/core-effect.ts +4 -4
  44. package/src/internal/core.ts +7 -7
  45. package/src/internal/fiberRuntime.ts +11 -11
  46. package/src/internal/pool.ts +9 -6
  47. package/src/internal/stm/core.ts +11 -11
  48. package/src/internal/version.ts +1 -1
package/src/Utils.ts CHANGED
@@ -786,9 +786,14 @@ export const structuralRegion = <A>(body: () => A, tester?: (a: unknown, b: unkn
786
786
  }
787
787
 
788
788
  const tracingFunction = (name: string) => {
789
- const internalCall = <A>(body: () => A): A => body()
790
- Object.defineProperty(internalCall, "name", { value: name })
791
- return internalCall
789
+ const wrap = {
790
+ [name]<A>(body: () => A) {
791
+ return body()
792
+ }
793
+ }
794
+ return function<A>(fn: () => A): A {
795
+ return wrap[name](fn)
796
+ }
792
797
  }
793
798
 
794
799
  /**
@@ -796,11 +801,4 @@ const tracingFunction = (name: string) => {
796
801
  * @status experimental
797
802
  * @category tracing
798
803
  */
799
- export const effect_internal_function = tracingFunction("effect_internal_function")
800
-
801
- /**
802
- * @since 3.2.2
803
- * @status experimental
804
- * @category tracing
805
- */
806
- export const effect_internal_generator = tracingFunction("effect_internal_generator")
804
+ export const internalCall = tracingFunction("effect_internal_function")
@@ -1061,12 +1061,10 @@ const prettyErrorStack = (message: string, stack: string, span?: Span | undefine
1061
1061
  const lines = stack.split("\n")
1062
1062
 
1063
1063
  for (let i = 1; i < lines.length; i++) {
1064
- if (lines[i].includes("effect_internal_function")) {
1065
- out.pop()
1064
+ if (lines[i].includes("Generator.next")) {
1066
1065
  break
1067
1066
  }
1068
- if (lines[i].includes("effect_internal_generator")) {
1069
- out.pop()
1067
+ if (lines[i].includes("effect_internal_function")) {
1070
1068
  out.pop()
1071
1069
  break
1072
1070
  }
@@ -1,4 +1,4 @@
1
- import { effect_internal_function, effect_internal_generator } from "effect/Utils"
1
+ import { internalCall } from "effect/Utils"
2
2
  import * as Arr from "../Array.js"
3
3
  import type * as Cause from "../Cause.js"
4
4
  import * as Chunk from "../Chunk.js"
@@ -772,7 +772,7 @@ export const gen: typeof Effect.gen = function() {
772
772
  }
773
773
  return core.suspend(() => {
774
774
  const iterator = f(pipe)
775
- const state = effect_internal_generator(() => iterator.next())
775
+ const state = internalCall(() => iterator.next())
776
776
  const run = (
777
777
  state: IteratorYieldResult<any> | IteratorReturnResult<any>
778
778
  ): Effect.Effect<any, any, any> => {
@@ -780,7 +780,7 @@ export const gen: typeof Effect.gen = function() {
780
780
  ? core.succeed(state.value)
781
781
  : core.flatMap(
782
782
  yieldWrapGet(state.value) as any,
783
- (val: any) => run(effect_internal_generator(() => iterator.next(val)))
783
+ (val: any) => run(internalCall(() => iterator.next(val)))
784
784
  ))
785
785
  }
786
786
  return run(state)
@@ -2185,7 +2185,7 @@ export const functionWithSpan = <Args extends Array<any>, Ret extends Effect.Eff
2185
2185
  ? options.options.apply(null, arguments as any)
2186
2186
  : options.options
2187
2187
  return withSpan(
2188
- core.suspend(() => effect_internal_function(() => options.body.apply(this, arguments as any))),
2188
+ core.suspend(() => internalCall(() => options.body.apply(this, arguments as any))),
2189
2189
  opts.name,
2190
2190
  {
2191
2191
  ...opts,
@@ -1,4 +1,4 @@
1
- import { effect_internal_function } from "effect/Utils"
1
+ import { internalCall } from "effect/Utils"
2
2
  import * as Arr from "../Array.js"
3
3
  import type * as Cause from "../Cause.js"
4
4
  import * as Chunk from "../Chunk.js"
@@ -534,9 +534,9 @@ export const async = <A, E = never, R = never>(
534
534
  let controllerRef: AbortController | void = undefined
535
535
  if (this.effect_instruction_i0.length !== 1) {
536
536
  controllerRef = new AbortController()
537
- cancelerRef = effect_internal_function(() => this.effect_instruction_i0(proxyResume, controllerRef!.signal))
537
+ cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume, controllerRef!.signal))
538
538
  } else {
539
- cancelerRef = effect_internal_function(() => (this.effect_instruction_i0 as any)(proxyResume))
539
+ cancelerRef = internalCall(() => (this.effect_instruction_i0 as any)(proxyResume))
540
540
  }
541
541
  return (cancelerRef || controllerRef) ?
542
542
  onInterrupt(effect, (_) => {
@@ -1007,8 +1007,8 @@ export const interruptibleMask = <A, E, R>(
1007
1007
  effect.effect_instruction_i0 = RuntimeFlagsPatch.enable(_runtimeFlags.Interruption)
1008
1008
  effect.effect_instruction_i1 = (oldFlags: RuntimeFlags.RuntimeFlags) =>
1009
1009
  _runtimeFlags.interruption(oldFlags)
1010
- ? effect_internal_function(() => this.effect_instruction_i0(interruptible))
1011
- : effect_internal_function(() => this.effect_instruction_i0(uninterruptible))
1010
+ ? internalCall(() => this.effect_instruction_i0(interruptible))
1011
+ : internalCall(() => this.effect_instruction_i0(uninterruptible))
1012
1012
  return effect
1013
1013
  })
1014
1014
 
@@ -1323,8 +1323,8 @@ export const uninterruptibleMask = <A, E, R>(
1323
1323
  effect.effect_instruction_i0 = RuntimeFlagsPatch.disable(_runtimeFlags.Interruption)
1324
1324
  effect.effect_instruction_i1 = (oldFlags: RuntimeFlags.RuntimeFlags) =>
1325
1325
  _runtimeFlags.interruption(oldFlags)
1326
- ? effect_internal_function(() => this.effect_instruction_i0(interruptible))
1327
- : effect_internal_function(() => this.effect_instruction_i0(uninterruptible))
1326
+ ? internalCall(() => this.effect_instruction_i0(interruptible))
1327
+ : internalCall(() => this.effect_instruction_i0(uninterruptible))
1328
1328
  return effect
1329
1329
  })
1330
1330
 
@@ -1,4 +1,4 @@
1
- import { effect_internal_function } from "effect/Utils"
1
+ import { internalCall } from "effect/Utils"
2
2
  import * as RA from "../Array.js"
3
3
  import * as Boolean from "../Boolean.js"
4
4
  import type * as Cause from "../Cause.js"
@@ -147,7 +147,7 @@ const contOpSuccess = {
147
147
  cont: core.OnSuccess,
148
148
  value: unknown
149
149
  ) => {
150
- return effect_internal_function(() => cont.effect_instruction_i1(value))
150
+ return internalCall(() => cont.effect_instruction_i1(value))
151
151
  },
152
152
  ["OnStep"]: (
153
153
  _: FiberRuntime<any, any>,
@@ -161,7 +161,7 @@ const contOpSuccess = {
161
161
  cont: core.OnSuccessAndFailure,
162
162
  value: unknown
163
163
  ) => {
164
- return effect_internal_function(() => cont.effect_instruction_i2(value))
164
+ return internalCall(() => cont.effect_instruction_i2(value))
165
165
  },
166
166
  [OpCodes.OP_REVERT_FLAGS]: (
167
167
  self: FiberRuntime<any, any>,
@@ -180,10 +180,10 @@ const contOpSuccess = {
180
180
  cont: core.While,
181
181
  value: unknown
182
182
  ) => {
183
- effect_internal_function(() => cont.effect_instruction_i2(value))
184
- if (effect_internal_function(() => cont.effect_instruction_i0())) {
183
+ internalCall(() => cont.effect_instruction_i2(value))
184
+ if (internalCall(() => cont.effect_instruction_i0())) {
185
185
  self.pushStack(cont)
186
- return effect_internal_function(() => cont.effect_instruction_i1())
186
+ return internalCall(() => cont.effect_instruction_i1())
187
187
  } else {
188
188
  return core.void
189
189
  }
@@ -1074,7 +1074,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
1074
1074
  }
1075
1075
 
1076
1076
  [OpCodes.OP_SYNC](op: core.Primitive & { _op: OpCodes.OP_SYNC }) {
1077
- const value = effect_internal_function(() => op.effect_instruction_i0())
1077
+ const value = internalCall(() => op.effect_instruction_i0())
1078
1078
  const cont = this.getNextSuccessCont()
1079
1079
  if (cont !== undefined) {
1080
1080
  if (!(cont._op in contOpSuccess)) {
@@ -1113,7 +1113,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
1113
1113
  case OpCodes.OP_ON_FAILURE:
1114
1114
  case OpCodes.OP_ON_SUCCESS_AND_FAILURE: {
1115
1115
  if (!(_runtimeFlags.interruptible(this._runtimeFlags) && this.isInterrupted())) {
1116
- return effect_internal_function(() => cont.effect_instruction_i1(cause))
1116
+ return internalCall(() => cont.effect_instruction_i1(cause))
1117
1117
  } else {
1118
1118
  return core.exitFailCause(internalCause.stripFailures(cause))
1119
1119
  }
@@ -1144,7 +1144,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
1144
1144
  }
1145
1145
 
1146
1146
  [OpCodes.OP_WITH_RUNTIME](op: core.Primitive & { _op: OpCodes.OP_WITH_RUNTIME }) {
1147
- return effect_internal_function(() =>
1147
+ return internalCall(() =>
1148
1148
  op.effect_instruction_i0(
1149
1149
  this as FiberRuntime<unknown, unknown>,
1150
1150
  FiberStatus.running(this._runtimeFlags) as FiberStatus.Running
@@ -1210,7 +1210,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
1210
1210
  // Since we updated the flags, we need to revert them
1211
1211
  const revertFlags = _runtimeFlags.diff(newRuntimeFlags, oldRuntimeFlags)
1212
1212
  this.pushStack(new core.RevertFlags(revertFlags, op))
1213
- return effect_internal_function(() => op.effect_instruction_i1!(oldRuntimeFlags))
1213
+ return internalCall(() => op.effect_instruction_i1!(oldRuntimeFlags))
1214
1214
  } else {
1215
1215
  return core.exitVoid
1216
1216
  }
@@ -1262,7 +1262,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
1262
1262
  }
1263
1263
 
1264
1264
  [OpCodes.OP_COMMIT](op: core.Primitive & { _op: OpCodes.OP_COMMIT }) {
1265
- return effect_internal_function(() => op.commit())
1265
+ return internalCall(() => op.commit())
1266
1266
  }
1267
1267
 
1268
1268
  /**
@@ -218,12 +218,15 @@ class PoolImpl<in out A, in out E> implements Pool.Pool<A, E> {
218
218
  const release = (attempted: Attempted<A, E>): Effect.Effect<unknown> =>
219
219
  core.exitMatch(attempted.result, {
220
220
  onFailure: () =>
221
- core.flatten(ref.modify(this.state, (state) => {
222
- if (state.size <= this.min) {
223
- return [allocateUinterruptible(this), { ...state, free: state.free + 1 }] as const
224
- }
225
- return [core.void, { ...state, size: state.size - 1 }] as const
226
- })),
221
+ core.zipRight(
222
+ attempted.finalizer,
223
+ core.flatten(ref.modify(this.state, (state) => {
224
+ if (state.size <= this.min) {
225
+ return [allocateUinterruptible(this), { ...state, free: state.free + 1 }] as const
226
+ }
227
+ return [core.void, { ...state, size: state.size - 1 }] as const
228
+ }))
229
+ ),
227
230
  onSuccess: (item) =>
228
231
  core.flatMap(ref.get(this.invalidated), (set) => {
229
232
  if (pipe(set, HashSet.has(item))) {
@@ -1,4 +1,4 @@
1
- import { effect_internal_function } from "effect/Utils"
1
+ import { internalCall } from "effect/Utils"
2
2
  import * as Cause from "../../Cause.js"
3
3
  import * as Context from "../../Context.js"
4
4
  import * as Effect from "../../Effect.js"
@@ -505,17 +505,17 @@ export class STMDriver<in out R, out E, out A> {
505
505
  case "Commit": {
506
506
  switch (current.effect_instruction_i0) {
507
507
  case OpCodes.OP_DIE: {
508
- exit = TExit.die(effect_internal_function(() => current.effect_instruction_i1()))
508
+ exit = TExit.die(internalCall(() => current.effect_instruction_i1()))
509
509
  break
510
510
  }
511
511
  case OpCodes.OP_FAIL: {
512
512
  const cont = this.nextFailure()
513
513
  if (cont === undefined) {
514
- exit = TExit.fail(effect_internal_function(() => current.effect_instruction_i1()))
514
+ exit = TExit.fail(internalCall(() => current.effect_instruction_i1()))
515
515
  } else {
516
- curr = effect_internal_function(() =>
516
+ curr = internalCall(() =>
517
517
  cont.effect_instruction_i2(
518
- effect_internal_function(() => current.effect_instruction_i1())
518
+ internalCall(() => current.effect_instruction_i1())
519
519
  ) as Primitive
520
520
  )
521
521
  }
@@ -526,7 +526,7 @@ export class STMDriver<in out R, out E, out A> {
526
526
  if (cont === undefined) {
527
527
  exit = TExit.retry
528
528
  } else {
529
- curr = effect_internal_function(() => cont.effect_instruction_i2() as Primitive)
529
+ curr = internalCall(() => cont.effect_instruction_i2() as Primitive)
530
530
  }
531
531
  break
532
532
  }
@@ -535,7 +535,7 @@ export class STMDriver<in out R, out E, out A> {
535
535
  break
536
536
  }
537
537
  case OpCodes.OP_WITH_STM_RUNTIME: {
538
- curr = effect_internal_function(() =>
538
+ curr = internalCall(() =>
539
539
  current.effect_instruction_i1(this as STMDriver<unknown, unknown, unknown>) as Primitive
540
540
  )
541
541
  break
@@ -549,7 +549,7 @@ export class STMDriver<in out R, out E, out A> {
549
549
  }
550
550
  case OpCodes.OP_PROVIDE: {
551
551
  const env = this.env
552
- this.env = effect_internal_function(() => current.effect_instruction_i2(env))
552
+ this.env = internalCall(() => current.effect_instruction_i2(env))
553
553
  curr = pipe(
554
554
  current.effect_instruction_i1,
555
555
  ensuring(sync(() => (this.env = env)))
@@ -562,17 +562,17 @@ export class STMDriver<in out R, out E, out A> {
562
562
  if (cont === undefined) {
563
563
  exit = TExit.succeed(value)
564
564
  } else {
565
- curr = effect_internal_function(() => cont.effect_instruction_i2(value) as Primitive)
565
+ curr = internalCall(() => cont.effect_instruction_i2(value) as Primitive)
566
566
  }
567
567
  break
568
568
  }
569
569
  case OpCodes.OP_SYNC: {
570
- const value = effect_internal_function(() => current.effect_instruction_i1())
570
+ const value = internalCall(() => current.effect_instruction_i1())
571
571
  const cont = this.nextSuccess()
572
572
  if (cont === undefined) {
573
573
  exit = TExit.succeed(value)
574
574
  } else {
575
- curr = effect_internal_function(() => cont.effect_instruction_i2(value) as Primitive)
575
+ curr = internalCall(() => cont.effect_instruction_i2(value) as Primitive)
576
576
  }
577
577
  break
578
578
  }
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.2.2"
1
+ let moduleVersion = "3.2.4"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4