effect 2.2.1 → 2.2.3

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/src/Effect.ts CHANGED
@@ -3095,7 +3095,7 @@ export const provide: {
3095
3095
 
3096
3096
  /**
3097
3097
  * Provides the effect with the single service it requires. If the effect
3098
- * requires more than one service use `provideContext` instead.
3098
+ * requires more than one service use `provide` instead.
3099
3099
  *
3100
3100
  * @since 2.0.0
3101
3101
  * @category context
@@ -3114,7 +3114,7 @@ export const provideService: {
3114
3114
 
3115
3115
  /**
3116
3116
  * Provides the effect with the single service it requires. If the effect
3117
- * requires more than one service use `provideContext` instead.
3117
+ * requires more than one service use `provide` instead.
3118
3118
  *
3119
3119
  * @since 2.0.0
3120
3120
  * @category context
@@ -3306,6 +3306,11 @@ export const either: <R, E, A>(self: Effect<R, E, A>) => Effect<R, never, Either
3306
3306
  export const exit: <R, E, A>(self: Effect<R, E, A>) => Effect<R, never, Exit.Exit<E, A>> = core.exit
3307
3307
 
3308
3308
  /**
3309
+ * Returns an effect that will succeed or fail the specified `Deferred` based
3310
+ * upon the result of the effect. Also synchronizes interruption, so if the
3311
+ * provided effect is interrupted, the specified `Deferred` will be interrupted
3312
+ * as well.
3313
+ *
3309
3314
  * @since 2.0.0
3310
3315
  * @category conversions
3311
3316
  */
@@ -1246,21 +1246,25 @@ export const mergeAllWith = (
1246
1246
  ),
1247
1247
  onSuccess: Either.match({
1248
1248
  onLeft: (outDone) =>
1249
- Effect.raceWith(Deferred.await(errorSignal), withPermits(concurrencyN)(Effect.unit), {
1250
- onSelfDone: (_, permitAcquisition) => Effect.as(Fiber.interrupt(permitAcquisition), false),
1251
- onOtherDone: (_, failureAwait) =>
1252
- Effect.zipRight(
1253
- Fiber.interrupt(failureAwait),
1254
- pipe(
1255
- Ref.get(lastDone),
1256
- Effect.flatMap(Option.match({
1257
- onNone: () => Queue.offer(queue, Effect.succeed(Either.left(outDone))),
1258
- onSome: (lastDone) => Queue.offer(queue, Effect.succeed(Either.left(f(lastDone, outDone))))
1259
- })),
1260
- Effect.as(false)
1249
+ Effect.raceWith(
1250
+ Effect.interruptible(Deferred.await(errorSignal)),
1251
+ Effect.interruptible(withPermits(concurrencyN)(Effect.unit)),
1252
+ {
1253
+ onSelfDone: (_, permitAcquisition) => Effect.as(Fiber.interrupt(permitAcquisition), false),
1254
+ onOtherDone: (_, failureAwait) =>
1255
+ Effect.zipRight(
1256
+ Fiber.interrupt(failureAwait),
1257
+ pipe(
1258
+ Ref.get(lastDone),
1259
+ Effect.flatMap(Option.match({
1260
+ onNone: () => Queue.offer(queue, Effect.succeed(Either.left(outDone))),
1261
+ onSome: (lastDone) => Queue.offer(queue, Effect.succeed(Either.left(f(lastDone, outDone))))
1262
+ })),
1263
+ Effect.as(false)
1264
+ )
1261
1265
  )
1262
- )
1263
- }),
1266
+ }
1267
+ ),
1264
1268
  onRight: (channel) =>
1265
1269
  _mergeStrategy.match(mergeStrategy, {
1266
1270
  onBackPressure: () =>
@@ -1273,7 +1277,7 @@ export const mergeAllWith = (
1273
1277
  Effect.flatMap((pull) =>
1274
1278
  Effect.race(
1275
1279
  evaluatePull(pull),
1276
- Deferred.await(errorSignal)
1280
+ Effect.interruptible(Deferred.await(errorSignal))
1277
1281
  )
1278
1282
  ),
1279
1283
  Effect.scoped
@@ -1306,8 +1310,8 @@ export const mergeAllWith = (
1306
1310
  Effect.flatMap((pull) =>
1307
1311
  pipe(
1308
1312
  evaluatePull(pull),
1309
- Effect.race(Deferred.await(errorSignal)),
1310
- Effect.race(Deferred.await(canceler))
1313
+ Effect.race(Effect.interruptible(Deferred.await(errorSignal))),
1314
+ Effect.race(Effect.interruptible(Deferred.await(canceler)))
1311
1315
  )
1312
1316
  ),
1313
1317
  Effect.scoped
@@ -35,16 +35,14 @@ const OP_COMPOSITE = "Composite" as const
35
35
  /** @internal */
36
36
  export type OP_COMPOSITE = typeof OP_COMPOSITE
37
37
 
38
+ const emptyHash = Hash.string(`${FiberIdSymbolKey}-${OP_NONE}`)
39
+
38
40
  /** @internal */
39
41
  class None implements FiberId.None {
40
42
  readonly [FiberIdTypeId]: FiberId.FiberIdTypeId = FiberIdTypeId
41
- readonly _tag = OP_NONE
42
- readonly _hash: number
43
- constructor() {
44
- this._hash = Hash.string(`${FiberIdSymbolKey}-${this._tag}`)
45
- }
43
+ readonly _tag = OP_NONE;
46
44
  [Hash.symbol](): number {
47
- return this._hash
45
+ return emptyHash
48
46
  }
49
47
  [Equal.symbol](that: unknown): boolean {
50
48
  return isFiberId(that) && that._tag === OP_NONE
@@ -67,14 +65,15 @@ class None implements FiberId.None {
67
65
  class Runtime implements FiberId.Runtime {
68
66
  readonly [FiberIdTypeId]: FiberId.FiberIdTypeId = FiberIdTypeId
69
67
  readonly _tag = OP_RUNTIME
70
- readonly _hash: number
71
68
  constructor(
72
69
  readonly id: number,
73
70
  readonly startTimeMillis: number
74
- ) {
75
- this._hash = Hash.string(`${FiberIdSymbolKey}-${this._tag}-${this.id}-${this.startTimeMillis}`)
76
- }
71
+ ) {}
72
+ _hash: number | undefined;
77
73
  [Hash.symbol](): number {
74
+ if (this._hash == undefined) {
75
+ this._hash = Hash.string(`${FiberIdSymbolKey}-${this._tag}-${this.id}-${this.startTimeMillis}`)
76
+ }
78
77
  return this._hash
79
78
  }
80
79
  [Equal.symbol](that: unknown): boolean {
@@ -103,18 +102,20 @@ class Runtime implements FiberId.Runtime {
103
102
  class Composite implements FiberId.Composite {
104
103
  readonly [FiberIdTypeId]: FiberId.FiberIdTypeId = FiberIdTypeId
105
104
  readonly _tag = OP_COMPOSITE
106
- readonly _hash: number
107
105
  constructor(
108
106
  readonly left: FiberId.FiberId,
109
107
  readonly right: FiberId.FiberId
110
108
  ) {
111
- this._hash = pipe(
112
- Hash.string(`${FiberIdSymbolKey}-${this._tag}`),
113
- Hash.combine(Hash.hash(this.left)),
114
- Hash.combine(Hash.hash(this.right))
115
- )
116
109
  }
110
+ _hash: number | undefined;
117
111
  [Hash.symbol](): number {
112
+ if (this._hash == undefined) {
113
+ this._hash = pipe(
114
+ Hash.string(`${FiberIdSymbolKey}-${this._tag}`),
115
+ Hash.combine(Hash.hash(this.left)),
116
+ Hash.combine(Hash.hash(this.right))
117
+ )
118
+ }
118
119
  return this._hash
119
120
  }
120
121
  [Equal.symbol](that: unknown): boolean {
@@ -5,7 +5,6 @@ import { dual, pipe } from "../Function.js"
5
5
  import { pipeArguments } from "../Pipeable.js"
6
6
  import type * as Scope from "../Scope.js"
7
7
  import type * as ScopedRef from "../ScopedRef.js"
8
- import * as effect from "./core-effect.js"
9
8
  import * as core from "./core.js"
10
9
  import * as circular from "./effect/circular.js"
11
10
  import * as fiberRuntime from "./fiberRuntime.js"
@@ -34,39 +33,30 @@ const close = <A>(self: ScopedRef.ScopedRef<A>): Effect.Effect<never, never, voi
34
33
  export const fromAcquire = <R, E, A>(
35
34
  acquire: Effect.Effect<R, E, A>
36
35
  ): Effect.Effect<R | Scope.Scope, E, ScopedRef.ScopedRef<A>> =>
37
- core.uninterruptibleMask((restore) =>
38
- pipe(
39
- fiberRuntime.scopeMake(),
40
- core.flatMap((newScope) =>
41
- pipe(
42
- restore(
43
- pipe(
44
- acquire,
45
- core.mapInputContext<R, Scope.Scope | R>(Context.add(fiberRuntime.scopeTag, newScope))
46
- )
47
- ),
48
- core.onError((cause) => newScope.close(core.exitFail(cause))),
49
- core.flatMap((value) =>
50
- pipe(
51
- circular.makeSynchronized([newScope, value] as const),
52
- core.flatMap((ref) => {
53
- const scopedRef: ScopedRef.ScopedRef<A> = {
54
- [ScopedRefTypeId]: scopedRefVariance,
55
- pipe() {
56
- return pipeArguments(this, arguments)
57
- },
58
- ref
59
- }
60
- return pipe(
61
- fiberRuntime.addFinalizer<R | Scope.Scope, void>(() => close(scopedRef)),
62
- core.as(scopedRef)
63
- )
64
- })
65
- )
36
+ core.uninterruptible(
37
+ fiberRuntime.scopeMake().pipe(core.flatMap((newScope) =>
38
+ acquire.pipe(
39
+ core.mapInputContext<R, Scope.Scope | R>(Context.add(fiberRuntime.scopeTag, newScope)),
40
+ core.onError((cause) => newScope.close(core.exitFail(cause))),
41
+ core.flatMap((value) =>
42
+ circular.makeSynchronized([newScope, value] as const).pipe(
43
+ core.flatMap((ref) => {
44
+ const scopedRef: ScopedRef.ScopedRef<A> = {
45
+ [ScopedRefTypeId]: scopedRefVariance,
46
+ pipe() {
47
+ return pipeArguments(this, arguments)
48
+ },
49
+ ref
50
+ }
51
+ return pipe(
52
+ fiberRuntime.addFinalizer<R | Scope.Scope, void>(() => close(scopedRef)),
53
+ core.as(scopedRef)
54
+ )
55
+ })
66
56
  )
67
57
  )
68
58
  )
69
- )
59
+ ))
70
60
  )
71
61
 
72
62
  /** @internal */
@@ -92,38 +82,28 @@ export const set = dual<
92
82
  ) =>
93
83
  core.flatten(
94
84
  synchronized.modifyEffect(self.ref, ([oldScope, value]) =>
95
- core.uninterruptibleMask((restore) =>
96
- pipe(
97
- fiberRuntime.scopeMake(),
85
+ core.uninterruptible(
86
+ core.scopeClose(oldScope, core.exitUnit).pipe(
87
+ core.zipRight(fiberRuntime.scopeMake()),
98
88
  core.flatMap((newScope) =>
99
- pipe(
100
- restore(
101
- pipe(
102
- acquire,
103
- core.mapInputContext<Exclude<R, Scope.Scope>, R>(
104
- Context.add(fiberRuntime.scopeTag, newScope) as any
105
- )
106
- )
107
- ),
108
- core.exit,
109
- core.flatMap(
110
- core.exitMatch({
89
+ core.exit(fiberRuntime.scopeExtend(acquire, newScope)).pipe(
90
+ core.flatMap((exit) =>
91
+ core.exitMatch(exit, {
111
92
  onFailure: (cause) =>
112
- pipe(
113
- newScope.close(core.exitUnit),
114
- effect.ignore,
93
+ core.scopeClose(newScope, core.exitUnit).pipe(
115
94
  core.as(
116
95
  [
117
- core.failCause(cause) as unknown as Effect.Effect<never, never, void>,
96
+ core.failCause(cause) as Effect.Effect<never, E, void>,
118
97
  [oldScope, value] as const
119
98
  ] as const
120
99
  )
121
100
  ),
122
101
  onSuccess: (value) =>
123
- pipe(
124
- oldScope.close(core.exitUnit),
125
- effect.ignore,
126
- core.as([core.unit, [newScope, value] as const] as const)
102
+ core.succeed(
103
+ [
104
+ core.unit as Effect.Effect<never, E, void>,
105
+ [newScope, value] as const
106
+ ] as const
127
107
  )
128
108
  })
129
109
  )
@@ -1 +1 @@
1
- export const moduleVersion = "2.2.1"
1
+ export const moduleVersion = "2.2.3"