effect 3.19.0 → 3.19.2

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/FiberMap.ts CHANGED
@@ -607,16 +607,20 @@ const runImpl = <K, A, E, R, XE extends E, XA extends A>(
607
607
  readonly propagateInterruption?: boolean | undefined
608
608
  }
609
609
  ) =>
610
- Effect.fiberIdWith((fiberId) => {
610
+ Effect.withFiberRuntime((parent) => {
611
611
  if (self.state._tag === "Closed") {
612
612
  return Effect.interrupt
613
613
  } else if (options?.onlyIfMissing === true && unsafeHas(self, key)) {
614
614
  return Effect.sync(constInterruptedFiber)
615
615
  }
616
- return Effect.tap(
617
- Effect.forkDaemon(effect),
618
- (fiber) => unsafeSet(self, key, fiber, { ...options, interruptAs: fiberId })
619
- )
616
+ const runtime = Runtime.make<R>({
617
+ context: parent.currentContext as any,
618
+ fiberRefs: parent.getFiberRefs(),
619
+ runtimeFlags: Runtime.defaultRuntime.runtimeFlags
620
+ })
621
+ const fiber = Runtime.runFork(runtime)(effect)
622
+ unsafeSet(self, key, fiber, { ...options, interruptAs: parent.id() })
623
+ return Effect.succeed(fiber)
620
624
  })
621
625
 
622
626
  /**
@@ -299,10 +299,10 @@ export const mergeAll = <T extends Array<unknown>>(
299
299
  ...ctxs: [...{ [K in keyof T]: C.Context<T[K]> }]
300
300
  ): C.Context<T[number]> => {
301
301
  const map = new Map()
302
- for (const ctx of ctxs) {
303
- for (const [tag, s] of ctx.unsafeMap) {
304
- map.set(tag, s)
305
- }
302
+ for (let i = 0; i < ctxs.length; i++) {
303
+ ctxs[i].unsafeMap.forEach((value, key) => {
304
+ map.set(key, value)
305
+ })
306
306
  }
307
307
  return makeContext(map)
308
308
  }
@@ -1,3 +1,4 @@
1
+ import type * as Arr from "../Array.js"
1
2
  import * as Cause from "../Cause.js"
2
3
  import * as Clock from "../Clock.js"
3
4
  import * as Context from "../Context.js"
@@ -24,6 +25,7 @@ import type * as Types from "../Types.js"
24
25
  import * as effect from "./core-effect.js"
25
26
  import * as core from "./core.js"
26
27
  import * as circular from "./effect/circular.js"
28
+ import * as ExecutionStrategy from "./executionStrategy.js"
27
29
  import * as fiberRuntime from "./fiberRuntime.js"
28
30
  import * as circularManagedRuntime from "./managedRuntime/circular.js"
29
31
  import * as EffectOpCodes from "./opCodes/effect.js"
@@ -84,6 +86,7 @@ export type Primitive =
84
86
  | ProvideTo
85
87
  | ZipWith
86
88
  | ZipWithPar
89
+ | MergeAll
87
90
 
88
91
  /** @internal */
89
92
  export type Op<Tag extends string, Body = {}> = Layer.Layer<unknown, unknown, unknown> & Body & {
@@ -168,6 +171,13 @@ export interface ZipWithPar extends
168
171
  }>
169
172
  {}
170
173
 
174
+ /** @internal */
175
+ export interface MergeAll extends
176
+ Op<OpCodes.OP_MERGE_ALL, {
177
+ readonly layers: Arr.NonEmptyReadonlyArray<Layer.Layer<unknown>>
178
+ }>
179
+ {}
180
+
171
181
  /** @internal */
172
182
  export const isLayer = (u: unknown): u is Layer.Layer<unknown, unknown, unknown> => hasProperty(u, LayerTypeId)
173
183
 
@@ -444,15 +454,41 @@ const makeBuilder = <RIn, E, ROut>(
444
454
  )
445
455
  }
446
456
  case "ZipWith": {
447
- return core.sync(() => (memoMap: Layer.MemoMap) =>
448
- pipe(
449
- memoMap.getOrElseMemoize(op.first, scope),
450
- fiberRuntime.zipWithOptions(
451
- memoMap.getOrElseMemoize(op.second, scope),
452
- op.zipK,
453
- { concurrent: true }
457
+ return core.gen(function*() {
458
+ const parallelScope = yield* core.scopeFork(scope, ExecutionStrategy.parallel)
459
+ const firstScope = yield* core.scopeFork(parallelScope, ExecutionStrategy.sequential)
460
+ const secondScope = yield* core.scopeFork(parallelScope, ExecutionStrategy.sequential)
461
+ return (memoMap: Layer.MemoMap) =>
462
+ pipe(
463
+ memoMap.getOrElseMemoize(op.first, firstScope),
464
+ fiberRuntime.zipWithOptions(
465
+ memoMap.getOrElseMemoize(op.second, secondScope),
466
+ op.zipK,
467
+ { concurrent: true }
468
+ )
454
469
  )
455
- )
470
+ })
471
+ }
472
+ case "MergeAll": {
473
+ const layers = op.layers
474
+ return core.map(
475
+ core.scopeFork(scope, ExecutionStrategy.parallel),
476
+ (parallelScope) => (memoMap: Layer.MemoMap) => {
477
+ const contexts = new Array<Context.Context<any>>(layers.length)
478
+ return core.map(
479
+ fiberRuntime.forEachConcurrentDiscard(
480
+ layers,
481
+ core.fnUntraced(function*(layer, i) {
482
+ const scope = yield* core.scopeFork(parallelScope, ExecutionStrategy.sequential)
483
+ const context = yield* memoMap.getOrElseMemoize(layer, scope)
484
+ contexts[i] = context
485
+ }),
486
+ false,
487
+ false
488
+ ),
489
+ () => Context.mergeAll(...contexts)
490
+ )
491
+ }
456
492
  )
457
493
  }
458
494
  }
@@ -788,11 +824,10 @@ export const mergeAll = <
788
824
  { [k in keyof Layers]: Layer.Layer.Error<Layers[k]> }[number],
789
825
  { [k in keyof Layers]: Layer.Layer.Context<Layers[k]> }[number]
790
826
  > => {
791
- let final = layers[0]
792
- for (let i = 1; i < layers.length; i++) {
793
- final = merge(final, layers[i])
794
- }
795
- return final as any
827
+ const mergeAll = Object.create(proto)
828
+ mergeAll._op_layer = OpCodes.OP_MERGE_ALL
829
+ mergeAll.layers = layers
830
+ return mergeAll as any
796
831
  }
797
832
 
798
833
  /** @internal */
@@ -46,6 +46,12 @@ export const OP_PROVIDE_MERGE = "ProvideMerge" as const
46
46
  /** @internal */
47
47
  export type OP_PROVIDE_MERGE = typeof OP_PROVIDE_MERGE
48
48
 
49
+ /** @internal */
50
+ export const OP_MERGE_ALL = "MergeAll" as const
51
+
52
+ /** @internal */
53
+ export type OP_MERGE_ALL = typeof OP_MERGE_ALL
54
+
49
55
  /** @internal */
50
56
  export const OP_ZIP_WITH = "ZipWith" as const
51
57
 
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.19.0"
1
+ let moduleVersion = "3.19.2"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4