effect 2.4.2 → 2.4.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 (87) hide show
  1. package/ManagedRuntime/package.json +6 -0
  2. package/dist/cjs/Brand.js +11 -38
  3. package/dist/cjs/Brand.js.map +1 -1
  4. package/dist/cjs/Effect.js.map +1 -1
  5. package/dist/cjs/Layer.js +9 -1
  6. package/dist/cjs/Layer.js.map +1 -1
  7. package/dist/cjs/ManagedRuntime.js +58 -0
  8. package/dist/cjs/ManagedRuntime.js.map +1 -0
  9. package/dist/cjs/Predicate.js +7 -1
  10. package/dist/cjs/Predicate.js.map +1 -1
  11. package/dist/cjs/Runtime.js.map +1 -1
  12. package/dist/cjs/index.js +4 -2
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/internal/blockedRequests.js +11 -7
  15. package/dist/cjs/internal/blockedRequests.js.map +1 -1
  16. package/dist/cjs/internal/core-effect.js +4 -4
  17. package/dist/cjs/internal/core-effect.js.map +1 -1
  18. package/dist/cjs/internal/core.js +4 -4
  19. package/dist/cjs/internal/core.js.map +1 -1
  20. package/dist/cjs/internal/fiberRuntime.js +3 -1
  21. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  22. package/dist/cjs/internal/layer.js +7 -4
  23. package/dist/cjs/internal/layer.js.map +1 -1
  24. package/dist/cjs/internal/managedRuntime.js +94 -0
  25. package/dist/cjs/internal/managedRuntime.js.map +1 -0
  26. package/dist/cjs/internal/runtime.js +13 -3
  27. package/dist/cjs/internal/runtime.js.map +1 -1
  28. package/dist/cjs/internal/version.js +1 -1
  29. package/dist/dts/Brand.d.ts +2 -1
  30. package/dist/dts/Brand.d.ts.map +1 -1
  31. package/dist/dts/Effect.d.ts +19 -15
  32. package/dist/dts/Effect.d.ts.map +1 -1
  33. package/dist/dts/Layer.d.ts +11 -0
  34. package/dist/dts/Layer.d.ts.map +1 -1
  35. package/dist/dts/ManagedRuntime.d.ts +100 -0
  36. package/dist/dts/ManagedRuntime.d.ts.map +1 -0
  37. package/dist/dts/Predicate.d.ts +5 -0
  38. package/dist/dts/Predicate.d.ts.map +1 -1
  39. package/dist/dts/Runtime.d.ts +6 -2
  40. package/dist/dts/Runtime.d.ts.map +1 -1
  41. package/dist/dts/index.d.ts +4 -0
  42. package/dist/dts/index.d.ts.map +1 -1
  43. package/dist/dts/internal/managedRuntime.d.ts +2 -0
  44. package/dist/dts/internal/managedRuntime.d.ts.map +1 -0
  45. package/dist/esm/Brand.js +9 -36
  46. package/dist/esm/Brand.js.map +1 -1
  47. package/dist/esm/Effect.js.map +1 -1
  48. package/dist/esm/Layer.js +8 -0
  49. package/dist/esm/Layer.js.map +1 -1
  50. package/dist/esm/ManagedRuntime.js +27 -0
  51. package/dist/esm/ManagedRuntime.js.map +1 -0
  52. package/dist/esm/Predicate.js +5 -0
  53. package/dist/esm/Predicate.js.map +1 -1
  54. package/dist/esm/Runtime.js.map +1 -1
  55. package/dist/esm/index.js +4 -0
  56. package/dist/esm/index.js.map +1 -1
  57. package/dist/esm/internal/blockedRequests.js +9 -6
  58. package/dist/esm/internal/blockedRequests.js.map +1 -1
  59. package/dist/esm/internal/core-effect.js +4 -4
  60. package/dist/esm/internal/core-effect.js.map +1 -1
  61. package/dist/esm/internal/core.js +5 -5
  62. package/dist/esm/internal/core.js.map +1 -1
  63. package/dist/esm/internal/fiberRuntime.js +3 -1
  64. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  65. package/dist/esm/internal/layer.js +5 -3
  66. package/dist/esm/internal/layer.js.map +1 -1
  67. package/dist/esm/internal/managedRuntime.js +62 -0
  68. package/dist/esm/internal/managedRuntime.js.map +1 -0
  69. package/dist/esm/internal/runtime.js +13 -3
  70. package/dist/esm/internal/runtime.js.map +1 -1
  71. package/dist/esm/internal/version.js +1 -1
  72. package/package.json +9 -1
  73. package/src/Brand.ts +23 -18
  74. package/src/Effect.ts +21 -16
  75. package/src/Layer.ts +17 -0
  76. package/src/ManagedRuntime.ts +119 -0
  77. package/src/Predicate.ts +8 -0
  78. package/src/Runtime.ts +7 -2
  79. package/src/index.ts +5 -0
  80. package/src/internal/blockedRequests.ts +29 -13
  81. package/src/internal/core-effect.ts +19 -25
  82. package/src/internal/core.ts +13 -13
  83. package/src/internal/fiberRuntime.ts +3 -1
  84. package/src/internal/layer.ts +25 -4
  85. package/src/internal/managedRuntime.ts +115 -0
  86. package/src/internal/runtime.ts +41 -21
  87. package/src/internal/version.ts +1 -1
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @since 2.0.0
3
+ */
4
+ import type * as Effect from "./Effect.js"
5
+ import type * as Exit from "./Exit.js"
6
+ import type * as Fiber from "./Fiber.js"
7
+ import * as internal from "./internal/managedRuntime.js"
8
+ import type * as Layer from "./Layer.js"
9
+ import type { Pipeable } from "./Pipeable.js"
10
+ import type * as Runtime from "./Runtime.js"
11
+
12
+ /**
13
+ * @since 2.0.0
14
+ * @category models
15
+ */
16
+ export interface ManagedRuntime<in R, out ER> extends Pipeable {
17
+ readonly memoMap: Layer.MemoMap
18
+ readonly runtimeEffect: Effect.Effect<Runtime.Runtime<R>, ER>
19
+ readonly runtime: () => Promise<Runtime.Runtime<R>>
20
+
21
+ /**
22
+ * Executes the effect using the provided Scheduler or using the global
23
+ * Scheduler if not provided
24
+ */
25
+ readonly runFork: <A, E>(
26
+ self: Effect.Effect<A, E, R>,
27
+ options?: Runtime.RunForkOptions
28
+ ) => Fiber.RuntimeFiber<A, E | ER>
29
+
30
+ /**
31
+ * Executes the effect synchronously returning the exit.
32
+ *
33
+ * This method is effectful and should only be invoked at the edges of your
34
+ * program.
35
+ */
36
+ readonly runSyncExit: <A, E>(effect: Effect.Effect<A, E, R>) => Exit.Exit<A, ER | E>
37
+
38
+ /**
39
+ * Executes the effect synchronously throwing in case of errors or async boundaries.
40
+ *
41
+ * This method is effectful and should only be invoked at the edges of your
42
+ * program.
43
+ */
44
+ readonly runSync: <A, E>(effect: Effect.Effect<A, E, R>) => A
45
+
46
+ /**
47
+ * Executes the effect asynchronously, eventually passing the exit value to
48
+ * the specified callback.
49
+ *
50
+ * This method is effectful and should only be invoked at the edges of your
51
+ * program.
52
+ */
53
+ readonly runCallback: <A, E>(
54
+ effect: Effect.Effect<A, E, R>,
55
+ options?: Runtime.RunCallbackOptions<A, E | ER> | undefined
56
+ ) => Runtime.Cancel<A, E | ER>
57
+
58
+ /**
59
+ * Runs the `Effect`, returning a JavaScript `Promise` that will be resolved
60
+ * with the value of the effect once the effect has been executed, or will be
61
+ * rejected with the first error or exception throw by the effect.
62
+ *
63
+ * This method is effectful and should only be used at the edges of your
64
+ * program.
65
+ */
66
+ readonly runPromise: <A, E>(effect: Effect.Effect<A, E, R>, options?: {
67
+ readonly signal?: AbortSignal | undefined
68
+ }) => Promise<A>
69
+
70
+ /**
71
+ * Runs the `Effect`, returning a JavaScript `Promise` that will be resolved
72
+ * with the `Exit` state of the effect once the effect has been executed.
73
+ *
74
+ * This method is effectful and should only be used at the edges of your
75
+ * program.
76
+ */
77
+ readonly runPromiseExit: <A, E>(effect: Effect.Effect<A, E, R>, options?: {
78
+ readonly signal?: AbortSignal | undefined
79
+ }) => Promise<Exit.Exit<A, ER | E>>
80
+
81
+ /**
82
+ * Dispose of the resources associated with the runtime.
83
+ */
84
+ readonly dispose: () => Promise<void>
85
+
86
+ /**
87
+ * Dispose of the resources associated with the runtime.
88
+ */
89
+ readonly disposeEffect: Effect.Effect<void, never, never>
90
+ }
91
+
92
+ /**
93
+ * Convert a Layer into an ManagedRuntime, that can be used to run Effect's using
94
+ * your services.
95
+ *
96
+ * @since 2.0.0
97
+ * @category runtime class
98
+ * @example
99
+ * import { Console, Effect, Layer, ManagedRuntime } from "effect"
100
+ *
101
+ * class Notifications extends Effect.Tag("Notifications")<
102
+ * Notifications,
103
+ * { readonly notify: (message: string) => Effect.Effect<void> }
104
+ * >() {
105
+ * static Live = Layer.succeed(this, { notify: (message) => Console.log(message) })
106
+ * }
107
+ *
108
+ * async function main() {
109
+ * const runtime = ManagedRuntime.make(Notifications.Live)
110
+ * await runtime.runPromise(Notifications.notify("Hello, world!"))
111
+ * await runtime.dispose()
112
+ * }
113
+ *
114
+ * main()
115
+ */
116
+ export const make: <R, E>(
117
+ layer: Layer.Layer<R, E, never>,
118
+ memoMap?: Layer.MemoMap | undefined
119
+ ) => ManagedRuntime<R, E> = internal.make
package/src/Predicate.ts CHANGED
@@ -543,6 +543,14 @@ export const isPromise = (
543
543
  ): input is Promise<unknown> =>
544
544
  hasProperty(input, "then") && "catch" in input && isFunction(input.then) && isFunction(input.catch)
545
545
 
546
+ /**
547
+ * @category guards
548
+ * @since 2.0.0
549
+ */
550
+ export const isPromiseLike = (
551
+ input: unknown
552
+ ): input is PromiseLike<unknown> => hasProperty(input, "then") && isFunction(input.then)
553
+
546
554
  /**
547
555
  * @since 2.0.0
548
556
  */
package/src/Runtime.ts CHANGED
@@ -134,7 +134,9 @@ export const runCallback: <R>(
134
134
  * @since 2.0.0
135
135
  * @category execution
136
136
  */
137
- export const runPromise: <R>(runtime: Runtime<R>) => <A, E>(effect: Effect.Effect<A, E, R>) => Promise<A> =
137
+ export const runPromise: <R>(
138
+ runtime: Runtime<R>
139
+ ) => <A, E>(effect: Effect.Effect<A, E, R>, options?: { readonly signal?: AbortSignal } | undefined) => Promise<A> =
138
140
  internal.unsafeRunPromise
139
141
 
140
142
  /**
@@ -149,7 +151,10 @@ export const runPromise: <R>(runtime: Runtime<R>) => <A, E>(effect: Effect.Effec
149
151
  */
150
152
  export const runPromiseExit: <R>(
151
153
  runtime: Runtime<R>
152
- ) => <A, E>(effect: Effect.Effect<A, E, R>) => Promise<Exit.Exit<A, E>> = internal.unsafeRunPromiseExit
154
+ ) => <A, E>(
155
+ effect: Effect.Effect<A, E, R>,
156
+ options?: { readonly signal?: AbortSignal } | undefined
157
+ ) => Promise<Exit.Exit<A, E>> = internal.unsafeRunPromiseExit
153
158
 
154
159
  /**
155
160
  * @since 2.0.0
package/src/index.ts CHANGED
@@ -385,6 +385,11 @@ export * as LogSpan from "./LogSpan.js"
385
385
  */
386
386
  export * as Logger from "./Logger.js"
387
387
 
388
+ /**
389
+ * @since 2.0.0
390
+ */
391
+ export * as ManagedRuntime from "./ManagedRuntime.js"
392
+
388
393
  /**
389
394
  * @since 1.0.0
390
395
  */
@@ -1,3 +1,4 @@
1
+ import * as Chunk from "../Chunk.js"
1
2
  import type * as Deferred from "../Deferred.js"
2
3
  import * as Either from "../Either.js"
3
4
  import * as Equal from "../Equal.js"
@@ -251,9 +252,9 @@ const step = (
251
252
  break
252
253
  }
253
254
  case "Single": {
254
- parallel = parallelCollectionCombine(
255
+ parallel = parallelCollectionAdd(
255
256
  parallel,
256
- parallelCollectionMake(current.dataSource, current.blockedRequest)
257
+ current
257
258
  )
258
259
  if (List.isNil(stack)) {
259
260
  return [parallel, sequential]
@@ -360,7 +361,7 @@ class ParallelImpl implements ParallelCollection {
360
361
  constructor(
361
362
  readonly map: HashMap.HashMap<
362
363
  RequestResolver.RequestResolver<unknown, unknown>,
363
- Array<Request.Entry<unknown>>
364
+ Chunk.Chunk<Request.Entry<unknown>>
364
365
  >
365
366
  ) {}
366
367
  }
@@ -372,7 +373,22 @@ export const parallelCollectionEmpty = (): ParallelCollection => new ParallelImp
372
373
  export const parallelCollectionMake = <A>(
373
374
  dataSource: RequestResolver.RequestResolver<A>,
374
375
  blockedRequest: Request.Entry<A>
375
- ): ParallelCollection => new ParallelImpl(HashMap.make([dataSource, Array.of(blockedRequest)]) as any)
376
+ ): ParallelCollection => new ParallelImpl(HashMap.make([dataSource, Chunk.of(blockedRequest)]) as any)
377
+
378
+ /** @internal */
379
+ export const parallelCollectionAdd = (
380
+ self: ParallelCollection,
381
+ blockedRequest: RequestBlock.Single
382
+ ): ParallelCollection =>
383
+ new ParallelImpl(HashMap.modifyAt(
384
+ self.map,
385
+ blockedRequest.dataSource,
386
+ (_) =>
387
+ Option.orElseSome(
388
+ Option.map(_, Chunk.append(blockedRequest.blockedRequest)),
389
+ () => Chunk.of(blockedRequest.blockedRequest)
390
+ )
391
+ ))
376
392
 
377
393
  /** @internal */
378
394
  export const parallelCollectionCombine = (
@@ -385,7 +401,7 @@ export const parallelCollectionCombine = (
385
401
  key,
386
402
  Option.match(HashMap.get(map, key), {
387
403
  onNone: () => value,
388
- onSome: (other) => [...value, ...other]
404
+ onSome: (other) => Chunk.appendAll(value, other)
389
405
  })
390
406
  )))
391
407
 
@@ -400,7 +416,7 @@ export const parallelCollectionKeys = (
400
416
  /** @internal */
401
417
  export const parallelCollectionToSequentialCollection = (
402
418
  self: ParallelCollection
403
- ): SequentialCollection => sequentialCollectionMake(HashMap.map(self.map, (x) => Array.of(x)) as any)
419
+ ): SequentialCollection => sequentialCollectionMake(HashMap.map(self.map, (x) => Chunk.of(x)) as any)
404
420
 
405
421
  // TODO
406
422
  // /** @internal */
@@ -423,7 +439,7 @@ class SequentialImpl implements SequentialCollection {
423
439
  constructor(
424
440
  readonly map: HashMap.HashMap<
425
441
  RequestResolver.RequestResolver<unknown, unknown>,
426
- Array<Array<Request.Entry<unknown>>>
442
+ Chunk.Chunk<Chunk.Chunk<Request.Entry<unknown>>>
427
443
  >
428
444
  ) {}
429
445
  }
@@ -432,7 +448,7 @@ class SequentialImpl implements SequentialCollection {
432
448
  export const sequentialCollectionMake = <A, R>(
433
449
  map: HashMap.HashMap<
434
450
  RequestResolver.RequestResolver<A, R>,
435
- Array<Array<Request.Entry<A>>>
451
+ Chunk.Chunk<Chunk.Chunk<Request.Entry<A>>>
436
452
  >
437
453
  ): SequentialCollection => new SequentialImpl(map as any)
438
454
 
@@ -446,8 +462,8 @@ export const sequentialCollectionCombine = (
446
462
  map,
447
463
  key,
448
464
  Option.match(HashMap.get(map, key), {
449
- onNone: () => [],
450
- onSome: (a) => [...a, ...value]
465
+ onNone: () => Chunk.empty(),
466
+ onSome: (a) => Chunk.appendAll(a, value)
451
467
  })
452
468
  )))
453
469
 
@@ -462,7 +478,7 @@ export const sequentialCollectionKeys = (
462
478
  /** @internal */
463
479
  export const sequentialCollectionToChunk = (
464
480
  self: SequentialCollection
465
- ): Array<[RequestResolver.RequestResolver<unknown>, Array<Array<Request.Entry<unknown>>>]> =>
481
+ ): Array<[RequestResolver.RequestResolver<unknown>, Chunk.Chunk<Chunk.Chunk<Request.Entry<unknown>>>]> =>
466
482
  Array.from(self.map) as any
467
483
 
468
484
  /** @internal */
@@ -472,7 +488,7 @@ export type RequestBlockParallelTypeId = typeof RequestBlockParallelTypeId
472
488
  export interface ParallelCollection extends ParallelCollection.Variance {
473
489
  readonly map: HashMap.HashMap<
474
490
  RequestResolver.RequestResolver<unknown, unknown>,
475
- Array<Request.Entry<unknown>>
491
+ Chunk.Chunk<Request.Entry<unknown>>
476
492
  >
477
493
  }
478
494
 
@@ -491,7 +507,7 @@ export type SequentialCollectionTypeId = typeof SequentialCollectionTypeId
491
507
  export interface SequentialCollection extends SequentialCollection.Variance {
492
508
  readonly map: HashMap.HashMap<
493
509
  RequestResolver.RequestResolver<unknown, unknown>,
494
- Array<Array<Request.Entry<unknown>>>
510
+ Chunk.Chunk<Chunk.Chunk<Request.Entry<unknown>>>
495
511
  >
496
512
  }
497
513
 
@@ -1171,17 +1171,15 @@ export const patchFiberRefs = (patch: FiberRefsPatch.FiberRefsPatch): Effect.Eff
1171
1171
  updateFiberRefs((fiberId, fiberRefs) => pipe(patch, fiberRefsPatch.patch(fiberId, fiberRefs)))
1172
1172
 
1173
1173
  /* @internal */
1174
- export const promise = <A>(evaluate: (signal: AbortSignal) => Promise<A>): Effect.Effect<A> =>
1174
+ export const promise = <A>(evaluate: (signal: AbortSignal) => PromiseLike<A>): Effect.Effect<A> =>
1175
1175
  evaluate.length >= 1
1176
1176
  ? core.async((resolve, signal) => {
1177
1177
  evaluate(signal)
1178
- .then((a) => resolve(core.exitSucceed(a)))
1179
- .catch((e) => resolve(core.exitDie(e)))
1178
+ .then((a) => resolve(core.exitSucceed(a)), (e) => resolve(core.exitDie(e)))
1180
1179
  })
1181
1180
  : core.async((resolve) => {
1182
- ;(evaluate as LazyArg<Promise<A>>)()
1183
- .then((a) => resolve(core.exitSucceed(a)))
1184
- .catch((e) => resolve(core.exitDie(e)))
1181
+ ;(evaluate as LazyArg<PromiseLike<A>>)()
1182
+ .then((a) => resolve(core.exitSucceed(a)), (e) => resolve(core.exitDie(e)))
1185
1183
  })
1186
1184
 
1187
1185
  /* @internal */
@@ -1620,23 +1618,23 @@ export const tracer: Effect.Effect<Tracer.Tracer> = tracerWith(core.succeed)
1620
1618
  export const tryPromise: {
1621
1619
  <A, E>(
1622
1620
  options: {
1623
- readonly try: (signal: AbortSignal) => Promise<A>
1621
+ readonly try: (signal: AbortSignal) => PromiseLike<A>
1624
1622
  readonly catch: (error: unknown) => E
1625
1623
  }
1626
1624
  ): Effect.Effect<A, E>
1627
- <A>(try_: (signal: AbortSignal) => Promise<A>): Effect.Effect<A, Cause.UnknownException>
1625
+ <A>(try_: (signal: AbortSignal) => PromiseLike<A>): Effect.Effect<A, Cause.UnknownException>
1628
1626
  } = <A, E>(
1629
- arg: ((signal: AbortSignal) => Promise<A>) | {
1630
- readonly try: (signal: AbortSignal) => Promise<A>
1627
+ arg: ((signal: AbortSignal) => PromiseLike<A>) | {
1628
+ readonly try: (signal: AbortSignal) => PromiseLike<A>
1631
1629
  readonly catch: (error: unknown) => E
1632
1630
  }
1633
1631
  ): Effect.Effect<A, E | Cause.UnknownException> => {
1634
- let evaluate: (signal?: AbortSignal) => Promise<A>
1632
+ let evaluate: (signal?: AbortSignal) => PromiseLike<A>
1635
1633
  let catcher: ((error: unknown) => E) | undefined = undefined
1636
1634
  if (typeof arg === "function") {
1637
- evaluate = arg as (signal?: AbortSignal) => Promise<A>
1635
+ evaluate = arg as (signal?: AbortSignal) => PromiseLike<A>
1638
1636
  } else {
1639
- evaluate = arg.try as (signal?: AbortSignal) => Promise<A>
1637
+ evaluate = arg.try as (signal?: AbortSignal) => PromiseLike<A>
1640
1638
  catcher = arg.catch
1641
1639
  }
1642
1640
 
@@ -1644,12 +1642,10 @@ export const tryPromise: {
1644
1642
  return core.async((resolve, signal) => {
1645
1643
  try {
1646
1644
  evaluate(signal)
1647
- .then((a) => resolve(core.exitSucceed(a)))
1648
- .catch((e) =>
1645
+ .then((a) => resolve(core.exitSucceed(a)), (e) =>
1649
1646
  resolve(core.fail(
1650
1647
  catcher ? catcher(e) : new core.UnknownException(e)
1651
- ))
1652
- )
1648
+ )))
1653
1649
  } catch (e) {
1654
1650
  resolve(core.fail(
1655
1651
  catcher ? catcher(e) : new core.UnknownException(e)
@@ -1661,12 +1657,10 @@ export const tryPromise: {
1661
1657
  return core.async((resolve) => {
1662
1658
  try {
1663
1659
  evaluate()
1664
- .then((a) => resolve(core.exitSucceed(a)))
1665
- .catch((e) =>
1660
+ .then((a) => resolve(core.exitSucceed(a)), (e) =>
1666
1661
  resolve(core.fail(
1667
1662
  catcher ? catcher(e) : new core.UnknownException(e)
1668
- ))
1669
- )
1663
+ )))
1670
1664
  } catch (e) {
1671
1665
  resolve(core.fail(
1672
1666
  catcher ? catcher(e) : new core.UnknownException(e)
@@ -1701,21 +1695,21 @@ export const tryMap = dual<
1701
1695
  export const tryMapPromise = dual<
1702
1696
  <A, B, E1>(
1703
1697
  options: {
1704
- readonly try: (a: A, signal: AbortSignal) => Promise<B>
1698
+ readonly try: (a: A, signal: AbortSignal) => PromiseLike<B>
1705
1699
  readonly catch: (error: unknown) => E1
1706
1700
  }
1707
1701
  ) => <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E | E1, R>,
1708
1702
  <A, E, R, B, E1>(
1709
1703
  self: Effect.Effect<A, E, R>,
1710
1704
  options: {
1711
- readonly try: (a: A, signal: AbortSignal) => Promise<B>
1705
+ readonly try: (a: A, signal: AbortSignal) => PromiseLike<B>
1712
1706
  readonly catch: (error: unknown) => E1
1713
1707
  }
1714
1708
  ) => Effect.Effect<B, E | E1, R>
1715
1709
  >(2, <A, E, R, B, E1>(
1716
1710
  self: Effect.Effect<A, E, R>,
1717
1711
  options: {
1718
- readonly try: (a: A, signal: AbortSignal) => Promise<B>
1712
+ readonly try: (a: A, signal: AbortSignal) => PromiseLike<B>
1719
1713
  readonly catch: (error: unknown) => E1
1720
1714
  }
1721
1715
  ) =>
@@ -1723,7 +1717,7 @@ export const tryMapPromise = dual<
1723
1717
  tryPromise({
1724
1718
  try: options.try.length >= 1
1725
1719
  ? (signal) => options.try(a, signal)
1726
- : () => (options.try as (a: A) => Promise<B>)(a),
1720
+ : () => (options.try as (a: A) => PromiseLike<B>)(a),
1727
1721
  catch: options.catch
1728
1722
  })))
1729
1723
 
@@ -26,7 +26,7 @@ import type * as MetricLabel from "../MetricLabel.js"
26
26
  import * as MutableRef from "../MutableRef.js"
27
27
  import * as Option from "../Option.js"
28
28
  import { pipeArguments } from "../Pipeable.js"
29
- import { hasProperty, isObject, isPromise, isString, type Predicate, type Refinement } from "../Predicate.js"
29
+ import { hasProperty, isObject, isPromiseLike, isString, type Predicate, type Refinement } from "../Predicate.js"
30
30
  import * as ReadonlyArray from "../ReadonlyArray.js"
31
31
  import type * as Request from "../Request.js"
32
32
  import type * as BlockedRequests from "../RequestBlock.js"
@@ -694,35 +694,35 @@ export const andThen: {
694
694
  ): <E, R>(
695
695
  self: Effect.Effect<A, E, R>
696
696
  ) => [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
697
- : [X] extends [Promise<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
697
+ : [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
698
698
  : Effect.Effect<X, E, R>
699
699
  <X>(
700
700
  f: NotFunction<X>
701
701
  ): <A, E, R>(
702
702
  self: Effect.Effect<A, E, R>
703
703
  ) => [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
704
- : [X] extends [Promise<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
704
+ : [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
705
705
  : Effect.Effect<X, E, R>
706
706
  <A, E, R, X>(
707
707
  self: Effect.Effect<A, E, R>,
708
708
  f: (a: NoInfer<A>) => X
709
709
  ): [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
710
- : [X] extends [Promise<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
710
+ : [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
711
711
  : Effect.Effect<X, E, R>
712
712
  <A, E, R, X>(
713
713
  self: Effect.Effect<A, E, R>,
714
714
  f: NotFunction<X>
715
715
  ): [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
716
- : [X] extends [Promise<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
716
+ : [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
717
717
  : Effect.Effect<X, E, R>
718
718
  } = dual(2, (self, f) =>
719
719
  flatMap(self, (a) => {
720
720
  const b = typeof f === "function" ? (f as any)(a) : f
721
721
  if (isEffect(b)) {
722
722
  return b
723
- } else if (isPromise(b)) {
723
+ } else if (isPromiseLike(b)) {
724
724
  return async<any, Cause.UnknownException>((resume) => {
725
- b.then((a) => resume(succeed(a))).catch((e) => resume(fail(new UnknownException(e))))
725
+ b.then((a) => resume(succeed(a)), (e) => resume(fail(new UnknownException(e))))
726
726
  })
727
727
  }
728
728
  return succeed(b)
@@ -1166,14 +1166,14 @@ export const tap = dual<
1166
1166
  ): <E, R>(
1167
1167
  self: Effect.Effect<A, E, R>
1168
1168
  ) => [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
1169
- : [X] extends [Promise<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
1169
+ : [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
1170
1170
  : Effect.Effect<A, E, R>
1171
1171
  <X>(
1172
1172
  f: NotFunction<X>
1173
1173
  ): <A, E, R>(
1174
1174
  self: Effect.Effect<A, E, R>
1175
1175
  ) => [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
1176
- : [X] extends [Promise<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
1176
+ : [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
1177
1177
  : Effect.Effect<A, E, R>
1178
1178
  },
1179
1179
  {
@@ -1181,13 +1181,13 @@ export const tap = dual<
1181
1181
  self: Effect.Effect<A, E, R>,
1182
1182
  f: (a: NoInfer<A>) => X
1183
1183
  ): [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
1184
- : [X] extends [Promise<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
1184
+ : [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
1185
1185
  : Effect.Effect<A, E, R>
1186
1186
  <A, E, R, X>(
1187
1187
  self: Effect.Effect<A, E, R>,
1188
1188
  f: NotFunction<X>
1189
1189
  ): [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
1190
- : [X] extends [Promise<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
1190
+ : [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
1191
1191
  : Effect.Effect<A, E, R>
1192
1192
  }
1193
1193
  >(2, (self, f) =>
@@ -1195,9 +1195,9 @@ export const tap = dual<
1195
1195
  const b = typeof f === "function" ? (f as any)(a) : f
1196
1196
  if (isEffect(b)) {
1197
1197
  return as(b, a)
1198
- } else if (isPromise(b)) {
1198
+ } else if (isPromiseLike(b)) {
1199
1199
  return async<any, Cause.UnknownException>((resume) => {
1200
- b.then((_) => resume(succeed(a))).catch((e) => resume(fail(new UnknownException(e))))
1200
+ b.then((_) => resume(succeed(a)), (e) => resume(fail(new UnknownException(e))))
1201
1201
  })
1202
1202
  }
1203
1203
  return succeed(a)
@@ -234,13 +234,15 @@ const runBlockedRequests = (self: RequestBlock.RequestBlock) =>
234
234
  _RequestBlock.sequentialCollectionToChunk(requestsByRequestResolver),
235
235
  ([dataSource, sequential]) => {
236
236
  const map = new Map<Request<any, any>, Entry<any>>()
237
+ const arr: Array<Array<Entry<any>>> = []
237
238
  for (const block of sequential) {
239
+ arr.push(Chunk.toReadonlyArray(block) as any)
238
240
  for (const entry of block) {
239
241
  map.set(entry.request as Request<any, any>, entry)
240
242
  }
241
243
  }
242
244
  return core.fiberRefLocally(
243
- invokeWithInterrupt(dataSource.runAll(sequential), sequential.flat()),
245
+ invokeWithInterrupt(dataSource.runAll(arr), arr.flat()),
244
246
  currentRequestMap,
245
247
  map
246
248
  )
@@ -312,6 +312,9 @@ export const makeMemoMap: Effect.Effect<Layer.MemoMap> = core.suspend(() =>
312
312
  )
313
313
  )
314
314
 
315
+ /** @internal */
316
+ export const unsafeMakeMemoMap = (): Layer.MemoMap => new MemoMapImpl(circular.unsafeMakeSynchronized(new Map()))
317
+
315
318
  /** @internal */
316
319
  export const build = <RIn, E, ROut>(
317
320
  self: Layer.Layer<ROut, E, RIn>
@@ -988,9 +991,9 @@ export const tapErrorCause = dual<
988
991
  /** @internal */
989
992
  export const toRuntime = <RIn, E, ROut>(
990
993
  self: Layer.Layer<ROut, E, RIn>
991
- ): Effect.Effect<Runtime.Runtime<ROut>, E, RIn | Scope.Scope> => {
992
- return pipe(
993
- fiberRuntime.scopeWith((scope) => pipe(self, buildWithScope(scope))),
994
+ ): Effect.Effect<Runtime.Runtime<ROut>, E, RIn | Scope.Scope> =>
995
+ pipe(
996
+ fiberRuntime.scopeWith((scope) => buildWithScope(self, scope)),
994
997
  core.flatMap((context) =>
995
998
  pipe(
996
999
  runtime.runtime<ROut>(),
@@ -998,7 +1001,25 @@ export const toRuntime = <RIn, E, ROut>(
998
1001
  )
999
1002
  )
1000
1003
  )
1001
- }
1004
+
1005
+ /** @internal */
1006
+ export const toRuntimeWithMemoMap = dual<
1007
+ (
1008
+ memoMap: Layer.MemoMap
1009
+ ) => <RIn, E, ROut>(self: Layer.Layer<ROut, E, RIn>) => Effect.Effect<Runtime.Runtime<ROut>, E, RIn | Scope.Scope>,
1010
+ <RIn, E, ROut>(
1011
+ self: Layer.Layer<ROut, E, RIn>,
1012
+ memoMap: Layer.MemoMap
1013
+ ) => Effect.Effect<Runtime.Runtime<ROut>, E, RIn | Scope.Scope>
1014
+ >(2, (self, memoMap) =>
1015
+ core.flatMap(
1016
+ fiberRuntime.scopeWith((scope) => buildWithMemoMap(self, memoMap, scope)),
1017
+ (context) =>
1018
+ pipe(
1019
+ runtime.runtime<any>(),
1020
+ core.provideContext(context)
1021
+ )
1022
+ ))
1002
1023
 
1003
1024
  /** @internal */
1004
1025
  export const provide = dual<