effect 3.13.12 → 3.14.0

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 (154) hide show
  1. package/LayerMap/package.json +6 -0
  2. package/dist/cjs/Array.js +29 -2
  3. package/dist/cjs/Array.js.map +1 -1
  4. package/dist/cjs/DateTime.js +16 -1
  5. package/dist/cjs/DateTime.js.map +1 -1
  6. package/dist/cjs/Effect.js +45 -3
  7. package/dist/cjs/Effect.js.map +1 -1
  8. package/dist/cjs/Either.js +35 -1
  9. package/dist/cjs/Either.js.map +1 -1
  10. package/dist/cjs/FiberSet.js +14 -2
  11. package/dist/cjs/FiberSet.js.map +1 -1
  12. package/dist/cjs/HashMap.js +11 -1
  13. package/dist/cjs/HashMap.js.map +1 -1
  14. package/dist/cjs/Layer.js +6 -1
  15. package/dist/cjs/Layer.js.map +1 -1
  16. package/dist/cjs/LayerMap.js +183 -0
  17. package/dist/cjs/LayerMap.js.map +1 -0
  18. package/dist/cjs/MutableHashMap.js +36 -4
  19. package/dist/cjs/MutableHashMap.js.map +1 -1
  20. package/dist/cjs/MutableRef.js.map +1 -1
  21. package/dist/cjs/Runtime.js.map +1 -1
  22. package/dist/cjs/TestClock.js +3 -2
  23. package/dist/cjs/TestClock.js.map +1 -1
  24. package/dist/cjs/Tracer.js.map +1 -1
  25. package/dist/cjs/index.js +4 -2
  26. package/dist/cjs/index.js.map +1 -1
  27. package/dist/cjs/internal/channel/channelExecutor.js +6 -1
  28. package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
  29. package/dist/cjs/internal/core-effect.js +13 -2
  30. package/dist/cjs/internal/core-effect.js.map +1 -1
  31. package/dist/cjs/internal/core.js +2 -1
  32. package/dist/cjs/internal/core.js.map +1 -1
  33. package/dist/cjs/internal/dateTime.js +3 -1
  34. package/dist/cjs/internal/dateTime.js.map +1 -1
  35. package/dist/cjs/internal/effect/circular.js +5 -0
  36. package/dist/cjs/internal/effect/circular.js.map +1 -1
  37. package/dist/cjs/internal/hashMap.js +3 -1
  38. package/dist/cjs/internal/hashMap.js.map +1 -1
  39. package/dist/cjs/internal/layer.js +7 -3
  40. package/dist/cjs/internal/layer.js.map +1 -1
  41. package/dist/cjs/internal/rcMap.js +11 -1
  42. package/dist/cjs/internal/rcMap.js.map +1 -1
  43. package/dist/cjs/internal/runtime.js +21 -21
  44. package/dist/cjs/internal/runtime.js.map +1 -1
  45. package/dist/cjs/internal/tracer.js +6 -2
  46. package/dist/cjs/internal/tracer.js.map +1 -1
  47. package/dist/cjs/internal/version.js +1 -1
  48. package/dist/cjs/internal/version.js.map +1 -1
  49. package/dist/dts/Array.d.ts +58 -0
  50. package/dist/dts/Array.d.ts.map +1 -1
  51. package/dist/dts/Data.d.ts +4 -4
  52. package/dist/dts/Data.d.ts.map +1 -1
  53. package/dist/dts/DateTime.d.ts +15 -0
  54. package/dist/dts/DateTime.d.ts.map +1 -1
  55. package/dist/dts/Effect.d.ts +66 -0
  56. package/dist/dts/Effect.d.ts.map +1 -1
  57. package/dist/dts/Either.d.ts +30 -0
  58. package/dist/dts/Either.d.ts.map +1 -1
  59. package/dist/dts/FiberSet.d.ts.map +1 -1
  60. package/dist/dts/HashMap.d.ts +31 -0
  61. package/dist/dts/HashMap.d.ts.map +1 -1
  62. package/dist/dts/Layer.d.ts +12 -0
  63. package/dist/dts/Layer.d.ts.map +1 -1
  64. package/dist/dts/LayerMap.d.ts +242 -0
  65. package/dist/dts/LayerMap.d.ts.map +1 -0
  66. package/dist/dts/MutableHashMap.d.ts +22 -0
  67. package/dist/dts/MutableHashMap.d.ts.map +1 -1
  68. package/dist/dts/MutableRef.d.ts +1 -0
  69. package/dist/dts/MutableRef.d.ts.map +1 -1
  70. package/dist/dts/Runtime.d.ts +144 -10
  71. package/dist/dts/Runtime.d.ts.map +1 -1
  72. package/dist/dts/TestClock.d.ts +3 -2
  73. package/dist/dts/TestClock.d.ts.map +1 -1
  74. package/dist/dts/Tracer.d.ts +1 -0
  75. package/dist/dts/Tracer.d.ts.map +1 -1
  76. package/dist/dts/index.d.ts +4 -0
  77. package/dist/dts/index.d.ts.map +1 -1
  78. package/dist/dts/internal/channel/channelExecutor.d.ts.map +1 -1
  79. package/dist/dts/internal/core-effect.d.ts.map +1 -1
  80. package/dist/dts/internal/layer.d.ts.map +1 -1
  81. package/dist/esm/Array.js +28 -1
  82. package/dist/esm/Array.js.map +1 -1
  83. package/dist/esm/DateTime.js +15 -0
  84. package/dist/esm/DateTime.js.map +1 -1
  85. package/dist/esm/Effect.js +42 -0
  86. package/dist/esm/Effect.js.map +1 -1
  87. package/dist/esm/Either.js +33 -0
  88. package/dist/esm/Either.js.map +1 -1
  89. package/dist/esm/FiberSet.js +13 -1
  90. package/dist/esm/FiberSet.js.map +1 -1
  91. package/dist/esm/HashMap.js +10 -0
  92. package/dist/esm/HashMap.js.map +1 -1
  93. package/dist/esm/Layer.js +5 -0
  94. package/dist/esm/Layer.js.map +1 -1
  95. package/dist/esm/LayerMap.js +172 -0
  96. package/dist/esm/LayerMap.js.map +1 -0
  97. package/dist/esm/MutableHashMap.js +33 -3
  98. package/dist/esm/MutableHashMap.js.map +1 -1
  99. package/dist/esm/MutableRef.js.map +1 -1
  100. package/dist/esm/Runtime.js.map +1 -1
  101. package/dist/esm/TestClock.js +3 -2
  102. package/dist/esm/TestClock.js.map +1 -1
  103. package/dist/esm/Tracer.js.map +1 -1
  104. package/dist/esm/index.js +4 -0
  105. package/dist/esm/index.js.map +1 -1
  106. package/dist/esm/internal/channel/channelExecutor.js +6 -1
  107. package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
  108. package/dist/esm/internal/core-effect.js +10 -0
  109. package/dist/esm/internal/core-effect.js.map +1 -1
  110. package/dist/esm/internal/core.js +2 -1
  111. package/dist/esm/internal/core.js.map +1 -1
  112. package/dist/esm/internal/dateTime.js +2 -0
  113. package/dist/esm/internal/dateTime.js.map +1 -1
  114. package/dist/esm/internal/effect/circular.js +5 -0
  115. package/dist/esm/internal/effect/circular.js.map +1 -1
  116. package/dist/esm/internal/hashMap.js +2 -0
  117. package/dist/esm/internal/hashMap.js.map +1 -1
  118. package/dist/esm/internal/layer.js +6 -2
  119. package/dist/esm/internal/layer.js.map +1 -1
  120. package/dist/esm/internal/rcMap.js +11 -1
  121. package/dist/esm/internal/rcMap.js.map +1 -1
  122. package/dist/esm/internal/runtime.js +21 -15
  123. package/dist/esm/internal/runtime.js.map +1 -1
  124. package/dist/esm/internal/tracer.js +6 -2
  125. package/dist/esm/internal/tracer.js.map +1 -1
  126. package/dist/esm/internal/version.js +1 -1
  127. package/dist/esm/internal/version.js.map +1 -1
  128. package/package.json +9 -1
  129. package/src/Array.ts +69 -1
  130. package/src/Data.ts +4 -4
  131. package/src/DateTime.ts +16 -0
  132. package/src/Effect.ts +143 -0
  133. package/src/Either.ts +36 -0
  134. package/src/FiberSet.ts +14 -1
  135. package/src/HashMap.ts +32 -0
  136. package/src/Layer.ts +14 -0
  137. package/src/LayerMap.ts +396 -0
  138. package/src/MutableHashMap.ts +45 -3
  139. package/src/MutableRef.ts +0 -2
  140. package/src/Runtime.ts +158 -20
  141. package/src/TestClock.ts +10 -3
  142. package/src/Tracer.ts +1 -0
  143. package/src/index.ts +5 -0
  144. package/src/internal/channel/channelExecutor.ts +11 -4
  145. package/src/internal/core-effect.ts +15 -0
  146. package/src/internal/core.ts +2 -1
  147. package/src/internal/dateTime.ts +3 -0
  148. package/src/internal/effect/circular.ts +5 -0
  149. package/src/internal/hashMap.ts +9 -0
  150. package/src/internal/layer.ts +14 -2
  151. package/src/internal/rcMap.ts +13 -3
  152. package/src/internal/runtime.ts +104 -38
  153. package/src/internal/tracer.ts +8 -1
  154. package/src/internal/version.ts +1 -1
package/src/TestClock.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  import * as Chunk from "./Chunk.js"
5
5
  import type * as Clock from "./Clock.js"
6
6
  import * as Context from "./Context.js"
7
+ import * as DateTime from "./DateTime.js"
7
8
  import type * as Deferred from "./Deferred.js"
8
9
  import * as Duration from "./Duration.js"
9
10
  import type * as Effect from "./Effect.js"
@@ -499,13 +500,19 @@ export const save = (): Effect.Effect<Effect.Effect<void>> => testClockWith((tes
499
500
 
500
501
  /**
501
502
  * Accesses a `TestClock` instance in the context and sets the clock time
502
- * to the specified `Instant`, running any actions scheduled for on or before
503
+ * to the specified `Instant` or `Date`, running any actions scheduled for on or before
503
504
  * the new time in order.
504
505
  *
505
506
  * @since 2.0.0
506
507
  */
507
- export const setTime = (instant: number): Effect.Effect<void> =>
508
- testClockWith((testClock) => testClock.setTime(instant))
508
+ export const setTime = (input: DateTime.DateTime.Input): Effect.Effect<void> =>
509
+ testClockWith((testClock) =>
510
+ testClock.setTime(
511
+ typeof input === "number"
512
+ ? input
513
+ : DateTime.unsafeMake(input).epochMillis
514
+ )
515
+ )
509
516
 
510
517
  /**
511
518
  * Semantically blocks the current fiber until the clock time is equal to or
package/src/Tracer.ts CHANGED
@@ -121,6 +121,7 @@ export interface Span {
121
121
  end(endTime: bigint, exit: Exit.Exit<unknown, unknown>): void
122
122
  attribute(key: string, value: unknown): void
123
123
  event(name: string, startTime: bigint, attributes?: Record<string, unknown>): void
124
+ addLinks(links: ReadonlyArray<SpanLink>): void
124
125
  }
125
126
 
126
127
  /**
package/src/index.ts CHANGED
@@ -406,6 +406,11 @@ export * as KeyedPool from "./KeyedPool.js"
406
406
  */
407
407
  export * as Layer from "./Layer.js"
408
408
 
409
+ /**
410
+ * @since 3.14.0
411
+ */
412
+ export * as LayerMap from "./LayerMap.js"
413
+
409
414
  /**
410
415
  * A data type for immutable linked lists representing ordered collections of elements of type `A`.
411
416
  *
@@ -7,7 +7,9 @@ import * as Effect from "../../Effect.js"
7
7
  import * as ExecutionStrategy from "../../ExecutionStrategy.js"
8
8
  import * as Exit from "../../Exit.js"
9
9
  import * as Fiber from "../../Fiber.js"
10
+ import * as FiberId from "../../FiberId.js"
10
11
  import { dual, identity, pipe } from "../../Function.js"
12
+ import * as HashSet from "../../HashSet.js"
11
13
  import * as Option from "../../Option.js"
12
14
  import * as Scope from "../../Scope.js"
13
15
  import type * as UpstreamPullStrategy from "../../UpstreamPullStrategy.js"
@@ -1143,8 +1145,9 @@ export const runIn = dual<
1143
1145
  restore(run(channelDeferred, scopeDeferred, child)).pipe(
1144
1146
  Effect.forkIn(scope),
1145
1147
  Effect.flatMap((fiber) =>
1146
- scope.addFinalizer(() =>
1147
- Deferred.isDone(channelDeferred).pipe(
1148
+ scope.addFinalizer((exit) => {
1149
+ const interruptors = Exit.isFailure(exit) ? Cause.interruptors(exit.cause) : undefined
1150
+ return Deferred.isDone(channelDeferred).pipe(
1148
1151
  Effect.flatMap((isDone) =>
1149
1152
  isDone
1150
1153
  ? Deferred.succeed(scopeDeferred, void 0).pipe(
@@ -1152,12 +1155,16 @@ export const runIn = dual<
1152
1155
  Effect.zipRight(Fiber.inheritAll(fiber))
1153
1156
  )
1154
1157
  : Deferred.succeed(scopeDeferred, void 0).pipe(
1155
- Effect.zipRight(Fiber.interrupt(fiber)),
1158
+ Effect.zipRight(
1159
+ interruptors && HashSet.size(interruptors) > 0
1160
+ ? Fiber.interruptAs(fiber, FiberId.combineAll(interruptors))
1161
+ : Fiber.interrupt(fiber)
1162
+ ),
1156
1163
  Effect.zipRight(Fiber.inheritAll(fiber))
1157
1164
  )
1158
1165
  )
1159
1166
  )
1160
- ).pipe(Effect.zipRight(restore(Deferred.await(channelDeferred))))
1167
+ }).pipe(Effect.zipRight(restore(Deferred.await(channelDeferred))))
1161
1168
  )
1162
1169
  )
1163
1170
  ))
@@ -1950,6 +1950,21 @@ export const annotateCurrentSpan: {
1950
1950
  ))
1951
1951
  }
1952
1952
 
1953
+ /* @internal */
1954
+ export const linkSpanCurrent: {
1955
+ (span: Tracer.AnySpan, attributes?: Readonly<Record<string, unknown>> | undefined): Effect.Effect<void>
1956
+ (links: ReadonlyArray<Tracer.SpanLink>): Effect.Effect<void>
1957
+ } = function(): Effect.Effect<void> {
1958
+ const args = arguments
1959
+ const links: ReadonlyArray<Tracer.SpanLink> = Array.isArray(args[0])
1960
+ ? args[0]
1961
+ : [{ _tag: "SpanLink", span: args[0], attributes: args[1] ?? {} }]
1962
+ return ignore(core.flatMap(
1963
+ currentSpan,
1964
+ (span) => core.sync(() => span.addLinks(links))
1965
+ ))
1966
+ }
1967
+
1953
1968
  /* @internal */
1954
1969
  export const annotateSpans = dual<
1955
1970
  {
@@ -3147,7 +3147,8 @@ const NoopSpanProto: Omit<Tracer.Span, "parent" | "name" | "context"> = {
3147
3147
  kind: "internal",
3148
3148
  attribute() {},
3149
3149
  event() {},
3150
- end() {}
3150
+ end() {},
3151
+ addLinks() {}
3151
3152
  }
3152
3153
 
3153
3154
  /** @internal */
@@ -299,6 +299,9 @@ export const makeZonedFromString = (input: string): Option.Option<DateTime.Zoned
299
299
  /** @internal */
300
300
  export const now: Effect.Effect<DateTime.Utc> = core.map(Clock.currentTimeMillis, makeUtc)
301
301
 
302
+ /** @internal */
303
+ export const nowAsDate: Effect.Effect<Date> = core.map(Clock.currentTimeMillis, (millis) => new Date(millis))
304
+
302
305
  /** @internal */
303
306
  export const unsafeNow: LazyArg<DateTime.Utc> = () => makeUtc(Date.now())
304
307
 
@@ -146,6 +146,11 @@ class Latch extends Effectable.Class<void> implements Effect.Latch {
146
146
  this.isOpen = true
147
147
  return this.unsafeSchedule(fiber)
148
148
  })
149
+ unsafeOpen() {
150
+ if (this.isOpen) return
151
+ this.isOpen = true
152
+ this.flushWaiters()
153
+ }
149
154
  release = core.withFiberRuntime<void>((fiber) => {
150
155
  if (this.isOpen) {
151
156
  return core.void
@@ -555,3 +555,12 @@ export const some: {
555
555
  return false
556
556
  }
557
557
  )
558
+
559
+ /** @internal */
560
+ export const every: {
561
+ <K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HM.HashMap<K, A>) => boolean
562
+ <K, A>(self: HM.HashMap<K, A>, predicate: (a: A, k: K) => boolean): boolean
563
+ } = Dual.dual(
564
+ 2,
565
+ <K, A>(self: HM.HashMap<K, A>, predicate: (a: A, k: K) => boolean): boolean => !some(self, (a, k) => !predicate(a, k))
566
+ )
@@ -67,6 +67,11 @@ export const MemoMapTypeId: Layer.MemoMapTypeId = Symbol.for(
67
67
  MemoMapTypeIdKey
68
68
  ) as Layer.MemoMapTypeId
69
69
 
70
+ /** @internal */
71
+ export const CurrentMemoMap = Context.Reference<Layer.CurrentMemoMap>()("effect/Layer/CurrentMemoMap", {
72
+ defaultValue: () => unsafeMakeMemoMap()
73
+ })
74
+
70
75
  /** @internal */
71
76
  export type Primitive =
72
77
  | ExtendScope
@@ -337,7 +342,7 @@ export const buildWithScope = dual<
337
342
  >(2, (self, scope) =>
338
343
  core.flatMap(
339
344
  makeMemoMap,
340
- (memoMap) => core.flatMap(makeBuilder(self, scope), (run) => run(memoMap))
345
+ (memoMap) => buildWithMemoMap(self, memoMap, scope)
341
346
  ))
342
347
 
343
348
  /** @internal */
@@ -351,7 +356,14 @@ export const buildWithMemoMap = dual<
351
356
  memoMap: Layer.MemoMap,
352
357
  scope: Scope.Scope
353
358
  ) => Effect.Effect<Context.Context<ROut>, E, RIn>
354
- >(3, (self, memoMap, scope) => core.flatMap(makeBuilder(self, scope), (run) => run(memoMap)))
359
+ >(
360
+ 3,
361
+ (self, memoMap, scope) =>
362
+ core.flatMap(
363
+ makeBuilder(self, scope),
364
+ (run) => effect.provideService(run(memoMap), CurrentMemoMap, memoMap)
365
+ )
366
+ )
355
367
 
356
368
  const makeBuilder = <RIn, E, ROut>(
357
369
  self: Layer.Layer<ROut, E, RIn>,
@@ -154,10 +154,16 @@ const acquire = core.fnUntraced(function*<K, A, E>(self: RcMapImpl<K, A, E>, key
154
154
  const scope = yield* fiberRuntime.scopeMake()
155
155
  const deferred = yield* core.deferredMake<A, E>()
156
156
  const acquire = self.lookup(key)
157
- yield* restore(core.fiberRefLocally(
157
+ const contextMap = new Map(self.context.unsafeMap)
158
+ yield* restore(core.mapInputContext(
158
159
  acquire as Effect<A, E>,
159
- core.currentContext,
160
- Context.add(self.context, fiberRuntime.scopeTag, scope)
160
+ (inputContext: Context.Context<never>) => {
161
+ inputContext.unsafeMap.forEach((value, key) => {
162
+ contextMap.set(key, value)
163
+ })
164
+ contextMap.set(fiberRuntime.scopeTag.key, scope)
165
+ return Context.unsafeMake(contextMap)
166
+ }
161
167
  )).pipe(
162
168
  core.exit,
163
169
  core.flatMap((exit) => core.deferredDone(deferred, exit)),
@@ -194,6 +200,10 @@ const release = <K, A, E>(self: RcMapImpl<K, A, E>, key: K, entry: State.Entry<A
194
200
  return core.scopeClose(entry.scope, core.exitVoid)
195
201
  }
196
202
 
203
+ if (!Duration.isFinite(self.idleTimeToLive)) {
204
+ return core.void
205
+ }
206
+
197
207
  entry.expiresAt = clock.unsafeCurrentTimeMillis() + Duration.toMillis(self.idleTimeToLive)
198
208
  if (entry.fiber) return core.void
199
209
 
@@ -26,9 +26,33 @@ import * as OpCodes from "./opCodes/effect.js"
26
26
  import * as runtimeFlags from "./runtimeFlags.js"
27
27
  import * as supervisor_ from "./supervisor.js"
28
28
 
29
+ const makeDual = <Args extends Array<any>, Return>(
30
+ f: (runtime: Runtime.Runtime<never>, effect: Effect.Effect<any, any>, ...args: Args) => Return
31
+ ): {
32
+ <R>(runtime: Runtime.Runtime<R>): <A, E>(effect: Effect.Effect<A, E, R>, ...args: Args) => Return
33
+ <R, A, E>(runtime: Runtime.Runtime<R>, effect: Effect.Effect<A, E, R>, ...args: Args): Return
34
+ } =>
35
+ function(this: any) {
36
+ if (arguments.length === 1) {
37
+ const runtime = arguments[0]
38
+ return (effect: any, ...args: Args) => f(runtime, effect, ...args)
39
+ }
40
+ return f.apply(this, arguments as any)
41
+ } as any
42
+
29
43
  /** @internal */
30
- export const unsafeFork = <R>(runtime: Runtime.Runtime<R>) =>
31
- <A, E>(
44
+ export const unsafeFork: {
45
+ <R>(runtime: Runtime.Runtime<R>): <A, E>(
46
+ effect: Effect.Effect<A, E, R>,
47
+ options?: Runtime.RunForkOptions | undefined
48
+ ) => Fiber.RuntimeFiber<A, E>
49
+ <R, A, E>(
50
+ runtime: Runtime.Runtime<R>,
51
+ effect: Effect.Effect<A, E, R>,
52
+ options?: Runtime.RunForkOptions | undefined
53
+ ): Fiber.RuntimeFiber<A, E>
54
+ } = makeDual(<R, A, E>(
55
+ runtime: Runtime.Runtime<R>,
32
56
  self: Effect.Effect<A, E, R>,
33
57
  options?: Runtime.RunForkOptions
34
58
  ): Fiber.RuntimeFiber<A, E> => {
@@ -93,15 +117,25 @@ export const unsafeFork = <R>(runtime: Runtime.Runtime<R>) =>
93
117
  }
94
118
 
95
119
  return fiberRuntime
96
- }
120
+ })
97
121
 
98
122
  /** @internal */
99
- export const unsafeRunCallback = <R>(runtime: Runtime.Runtime<R>) =>
100
- <A, E>(
101
- effect: Effect.Effect<A, E, R>,
102
- options: Runtime.RunCallbackOptions<A, E> = {}
103
- ): (fiberId?: FiberId.FiberId, options?: Runtime.RunCallbackOptions<A, E> | undefined) => void => {
104
- const fiberRuntime = unsafeFork(runtime)(effect, options)
123
+ export const unsafeRunCallback: {
124
+ <R>(runtime: Runtime.Runtime<R>): <A, E>(
125
+ effect: Effect.Effect<A, E, R>,
126
+ options?: Runtime.RunCallbackOptions<A, E> | undefined
127
+ ) => (fiberId?: FiberId.FiberId, options?: Runtime.RunCallbackOptions<A, E> | undefined) => void
128
+ <R, A, E>(
129
+ runtime: Runtime.Runtime<R>,
130
+ effect: Effect.Effect<A, E, R>,
131
+ options?: Runtime.RunCallbackOptions<A, E> | undefined
132
+ ): (fiberId?: FiberId.FiberId, options?: Runtime.RunCallbackOptions<A, E> | undefined) => void
133
+ } = makeDual((
134
+ runtime,
135
+ effect,
136
+ options: Runtime.RunCallbackOptions<any, any> = {}
137
+ ): (fiberId?: FiberId.FiberId, options?: Runtime.RunCallbackOptions<any, any> | undefined) => void => {
138
+ const fiberRuntime = unsafeFork(runtime, effect, options)
105
139
 
106
140
  if (options.onExit) {
107
141
  fiberRuntime.addObserver((exit) => {
@@ -119,17 +153,19 @@ export const unsafeRunCallback = <R>(runtime: Runtime.Runtime<R>) =>
119
153
  : undefined
120
154
  }
121
155
  )
122
- }
156
+ })
123
157
 
124
158
  /** @internal */
125
- export const unsafeRunSync = <R>(runtime: Runtime.Runtime<R>) => <A, E>(effect: Effect.Effect<A, E, R>): A => {
159
+ export const unsafeRunSync: {
160
+ <A, E, R>(runtime: Runtime.Runtime<R>, effect: Effect.Effect<A, E, R>): A
161
+ <R>(runtime: Runtime.Runtime<R>): <A, E>(effect: Effect.Effect<A, E, R>) => A
162
+ } = makeDual((runtime, effect) => {
126
163
  const result = unsafeRunSyncExit(runtime)(effect)
127
164
  if (result._tag === "Failure") {
128
165
  throw fiberFailure(result.effect_instruction_i0)
129
- } else {
130
- return result.effect_instruction_i0
131
166
  }
132
- }
167
+ return result.effect_instruction_i0
168
+ })
133
169
 
134
170
  class AsyncFiberExceptionImpl<A, E = never> extends Error implements Runtime.AsyncFiberException<A, E> {
135
171
  readonly _tag = "AsyncFiberException"
@@ -229,31 +265,47 @@ const fastPath = <A, E, R>(effect: Effect.Effect<A, E, R>): Exit.Exit<A, E> | un
229
265
  }
230
266
 
231
267
  /** @internal */
232
- export const unsafeRunSyncExit =
233
- <R>(runtime: Runtime.Runtime<R>) => <A, E>(effect: Effect.Effect<A, E, R>): Exit.Exit<A, E> => {
234
- const op = fastPath(effect)
235
- if (op) {
236
- return op
237
- }
238
- const scheduler = new scheduler_.SyncScheduler()
239
- const fiberRuntime = unsafeFork(runtime)(effect, { scheduler })
240
- scheduler.flush()
241
- const result = fiberRuntime.unsafePoll()
242
- if (result) {
243
- return result
244
- }
245
- return core.exitDie(core.capture(asyncFiberException(fiberRuntime), core.currentSpanFromFiber(fiberRuntime)))
268
+ export const unsafeRunSyncExit: {
269
+ <A, E, R>(runtime: Runtime.Runtime<R>, effect: Effect.Effect<A, E, R>): Exit.Exit<A, E>
270
+ <R>(runtime: Runtime.Runtime<R>): <A, E>(effect: Effect.Effect<A, E, R>) => Exit.Exit<A, E>
271
+ } = makeDual((runtime, effect) => {
272
+ const op = fastPath(effect)
273
+ if (op) {
274
+ return op
246
275
  }
276
+ const scheduler = new scheduler_.SyncScheduler()
277
+ const fiberRuntime = unsafeFork(runtime)(effect, { scheduler })
278
+ scheduler.flush()
279
+ const result = fiberRuntime.unsafePoll()
280
+ if (result) {
281
+ return result
282
+ }
283
+ return core.exitDie(core.capture(asyncFiberException(fiberRuntime), core.currentSpanFromFiber(fiberRuntime)))
284
+ })
247
285
 
248
286
  /** @internal */
249
- export const unsafeRunPromise = <R>(runtime: Runtime.Runtime<R>) =>
250
- <A, E>(
251
- effect: Effect.Effect<A, E, R>,
287
+ export const unsafeRunPromise: {
288
+ <R>(runtime: Runtime.Runtime<R>): <A, E>(
289
+ effect: Effect.Effect<A, E, R>,
290
+ options?: {
291
+ readonly signal?: AbortSignal | undefined
292
+ } | undefined
293
+ ) => Promise<A>
294
+ <R, A, E>(
295
+ runtime: Runtime.Runtime<R>,
296
+ effect: Effect.Effect<A, E, R>,
297
+ options?: {
298
+ readonly signal?: AbortSignal | undefined
299
+ } | undefined
300
+ ): Promise<A>
301
+ } = makeDual((
302
+ runtime,
303
+ effect,
252
304
  options?: {
253
305
  readonly signal?: AbortSignal | undefined
254
306
  } | undefined
255
- ): Promise<A> =>
256
- unsafeRunPromiseExit(runtime)(effect, options).then((result) => {
307
+ ) =>
308
+ unsafeRunPromiseExit(runtime, effect, options).then((result) => {
257
309
  switch (result._tag) {
258
310
  case OpCodes.OP_SUCCESS: {
259
311
  return result.effect_instruction_i0
@@ -263,16 +315,29 @@ export const unsafeRunPromise = <R>(runtime: Runtime.Runtime<R>) =>
263
315
  }
264
316
  }
265
317
  })
318
+ )
266
319
 
267
320
  /** @internal */
268
- export const unsafeRunPromiseExit = <R>(runtime: Runtime.Runtime<R>) =>
269
- <A, E>(
270
- effect: Effect.Effect<A, E, R>,
321
+ export const unsafeRunPromiseExit: {
322
+ <R>(
323
+ runtime: Runtime.Runtime<R>
324
+ ): <A, E>(
325
+ effect: Effect.Effect<A, E, R>,
326
+ options?: { readonly signal?: AbortSignal | undefined } | undefined
327
+ ) => Promise<Exit.Exit<A, E>>
328
+ <R, A, E>(
329
+ runtime: Runtime.Runtime<R>,
330
+ effect: Effect.Effect<A, E, R>,
331
+ options?: { readonly signal?: AbortSignal | undefined } | undefined
332
+ ): Promise<Exit.Exit<A, E>>
333
+ } = makeDual((
334
+ runtime,
335
+ effect,
271
336
  options?: {
272
337
  readonly signal?: AbortSignal | undefined
273
338
  } | undefined
274
- ): Promise<Exit.Exit<A, E>> =>
275
- new Promise((resolve) => {
339
+ ) =>
340
+ new Promise<Exit.Exit<any, any>>((resolve) => {
276
341
  const op = fastPath(effect)
277
342
  if (op) {
278
343
  resolve(op)
@@ -291,6 +356,7 @@ export const unsafeRunPromiseExit = <R>(runtime: Runtime.Runtime<R>) =>
291
356
  }
292
357
  }
293
358
  })
359
+ )
294
360
 
295
361
  /** @internal */
296
362
  export class RuntimeImpl<in R> implements Runtime.Runtime<R> {
@@ -44,12 +44,13 @@ export class NativeSpan implements Tracer.Span {
44
44
  status: Tracer.SpanStatus
45
45
  attributes: Map<string, unknown>
46
46
  events: Array<[name: string, startTime: bigint, attributes: Record<string, unknown>]> = []
47
+ links: Array<Tracer.SpanLink>
47
48
 
48
49
  constructor(
49
50
  readonly name: string,
50
51
  readonly parent: Option.Option<Tracer.AnySpan>,
51
52
  readonly context: Context.Context<never>,
52
- readonly links: ReadonlyArray<Tracer.SpanLink>,
53
+ links: Iterable<Tracer.SpanLink>,
53
54
  readonly startTime: bigint,
54
55
  readonly kind: Tracer.SpanKind
55
56
  ) {
@@ -60,6 +61,7 @@ export class NativeSpan implements Tracer.Span {
60
61
  this.attributes = new Map()
61
62
  this.traceId = parent._tag === "Some" ? parent.value.traceId : randomHexString(32)
62
63
  this.spanId = randomHexString(16)
64
+ this.links = Array.from(links)
63
65
  }
64
66
 
65
67
  end(endTime: bigint, exit: Exit.Exit<unknown, unknown>): void {
@@ -78,6 +80,11 @@ export class NativeSpan implements Tracer.Span {
78
80
  event(name: string, startTime: bigint, attributes?: Record<string, unknown>): void {
79
81
  this.events.push([name, startTime, attributes ?? {}])
80
82
  }
83
+
84
+ addLinks(links: ReadonlyArray<Tracer.SpanLink>): void {
85
+ // eslint-disable-next-line no-restricted-syntax
86
+ this.links.push(...links)
87
+ }
81
88
  }
82
89
 
83
90
  /** @internal */
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.13.12"
1
+ let moduleVersion = "3.14.0"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4