effect 3.4.5 → 3.4.7

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 (35) hide show
  1. package/dist/cjs/Micro.js +481 -425
  2. package/dist/cjs/Micro.js.map +1 -1
  3. package/dist/cjs/internal/channel.js +5 -2
  4. package/dist/cjs/internal/channel.js.map +1 -1
  5. package/dist/cjs/internal/core-effect.js +14 -11
  6. package/dist/cjs/internal/core-effect.js.map +1 -1
  7. package/dist/cjs/internal/fiberRuntime.js +4 -9
  8. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  9. package/dist/cjs/internal/pubsub.js +13 -2
  10. package/dist/cjs/internal/pubsub.js.map +1 -1
  11. package/dist/cjs/internal/version.js +1 -1
  12. package/dist/dts/Match.d.ts +14 -14
  13. package/dist/dts/Match.d.ts.map +1 -1
  14. package/dist/dts/Micro.d.ts +344 -260
  15. package/dist/dts/Micro.d.ts.map +1 -1
  16. package/dist/dts/internal/core-effect.d.ts.map +1 -1
  17. package/dist/esm/Micro.js +456 -402
  18. package/dist/esm/Micro.js.map +1 -1
  19. package/dist/esm/internal/channel.js +5 -2
  20. package/dist/esm/internal/channel.js.map +1 -1
  21. package/dist/esm/internal/core-effect.js +11 -9
  22. package/dist/esm/internal/core-effect.js.map +1 -1
  23. package/dist/esm/internal/fiberRuntime.js +4 -9
  24. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  25. package/dist/esm/internal/pubsub.js +13 -2
  26. package/dist/esm/internal/pubsub.js.map +1 -1
  27. package/dist/esm/internal/version.js +1 -1
  28. package/package.json +1 -1
  29. package/src/Match.ts +16 -16
  30. package/src/Micro.ts +715 -603
  31. package/src/internal/channel.ts +17 -19
  32. package/src/internal/core-effect.ts +14 -10
  33. package/src/internal/fiberRuntime.ts +4 -10
  34. package/src/internal/pubsub.ts +13 -2
  35. package/src/internal/version.ts +1 -1
@@ -8,6 +8,7 @@ import * as Either from "../Either.js"
8
8
  import * as Equal from "../Equal.js"
9
9
  import * as Exit from "../Exit.js"
10
10
  import * as Fiber from "../Fiber.js"
11
+ import * as FiberRef from "../FiberRef.js"
11
12
  import { constVoid, dual, identity, pipe } from "../Function.js"
12
13
  import type { LazyArg } from "../Function.js"
13
14
  import * as Layer from "../Layer.js"
@@ -28,6 +29,7 @@ import * as mergeDecision from "./channel/mergeDecision.js"
28
29
  import * as mergeState from "./channel/mergeState.js"
29
30
  import * as _mergeStrategy from "./channel/mergeStrategy.js"
30
31
  import * as singleProducerAsyncInput from "./channel/singleProducerAsyncInput.js"
32
+ import * as coreEffect from "./core-effect.js"
31
33
  import * as core from "./core-stream.js"
32
34
  import * as MergeDecisionOpCodes from "./opCodes/channelMergeDecision.js"
33
35
  import * as MergeStateOpCodes from "./opCodes/channelMergeState.js"
@@ -2326,29 +2328,25 @@ export const withSpan: {
2326
2328
  const dataFirst = typeof arguments[0] !== "string"
2327
2329
  const name = dataFirst ? arguments[1] : arguments[0]
2328
2330
  const options = tracer.addSpanStackTrace(dataFirst ? arguments[2] : arguments[1])
2331
+ const acquire = Effect.all([
2332
+ Effect.makeSpan(name, options),
2333
+ Effect.context(),
2334
+ Effect.clock,
2335
+ FiberRef.get(FiberRef.currentTracerTimingEnabled)
2336
+ ])
2329
2337
  if (dataFirst) {
2330
2338
  const self = arguments[0]
2331
- return unwrapScoped(
2332
- Effect.flatMap(
2333
- Effect.context(),
2334
- (context) =>
2335
- Effect.map(
2336
- Effect.makeSpanScoped(name, options),
2337
- (span) => core.provideContext(self, Context.add(context, tracer.spanTag, span))
2338
- )
2339
- )
2339
+ return acquireUseRelease(
2340
+ acquire,
2341
+ ([span, context]) => core.provideContext(self, Context.add(context, tracer.spanTag, span)),
2342
+ ([span, , clock, timingEnabled], exit) => coreEffect.endSpan(span, exit, clock, timingEnabled)
2340
2343
  )
2341
2344
  }
2342
- return (self: Effect.Effect<any, any, any>) =>
2343
- unwrapScoped(
2344
- Effect.flatMap(
2345
- Effect.context(),
2346
- (context) =>
2347
- Effect.map(
2348
- Effect.makeSpanScoped(name, options),
2349
- (span) => core.provideContext(self, Context.add(context, tracer.spanTag, span))
2350
- )
2351
- )
2345
+ return (self: Channel.Channel<any>) =>
2346
+ acquireUseRelease(
2347
+ acquire,
2348
+ ([span, context]) => core.provideContext(self, Context.add(context, tracer.spanTag, span)),
2349
+ ([span, , clock, timingEnabled], exit) => coreEffect.endSpan(span, exit, clock, timingEnabled)
2352
2350
  )
2353
2351
  } as any
2354
2352
 
@@ -1,3 +1,4 @@
1
+ import type { Exit } from "effect/Exit"
1
2
  import { internalCall } from "effect/Utils"
2
3
  import * as Arr from "../Array.js"
3
4
  import type * as Cause from "../Cause.js"
@@ -2122,6 +2123,18 @@ export const spanAnnotations: Effect.Effect<HashMap.HashMap<string, unknown>> =
2122
2123
  export const spanLinks: Effect.Effect<Chunk.Chunk<Tracer.SpanLink>> = core
2123
2124
  .fiberRefGet(core.currentTracerSpanLinks)
2124
2125
 
2126
+ /** @internal */
2127
+ export const endSpan = <A, E>(span: Tracer.Span, exit: Exit<A, E>, clock: Clock.Clock, timingEnabled: boolean) =>
2128
+ core.sync(() => {
2129
+ if (span.status._tag === "Ended") {
2130
+ return
2131
+ }
2132
+ if (core.exitIsFailure(exit) && internalCause.spanToTrace.has(span)) {
2133
+ span.attribute("code.stacktrace", internalCause.spanToTrace.get(span)!())
2134
+ }
2135
+ span.end(timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0, exit)
2136
+ })
2137
+
2125
2138
  /** @internal */
2126
2139
  export const useSpan: {
2127
2140
  <A, E, R>(name: string, evaluate: (span: Tracer.Span) => Effect.Effect<A, E, R>): Effect.Effect<A, E, R>
@@ -2144,16 +2157,7 @@ export const useSpan: {
2144
2157
  const span = unsafeMakeSpan(fiber, name, options)
2145
2158
  const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
2146
2159
  const clock = Context.get(fiber.getFiberRef(defaultServices.currentServices), clockTag)
2147
- return core.onExit(evaluate(span), (exit) =>
2148
- core.sync(() => {
2149
- if (span.status._tag === "Ended") {
2150
- return
2151
- }
2152
- if (core.exitIsFailure(exit) && internalCause.spanToTrace.has(span)) {
2153
- span.attribute("code.stacktrace", internalCause.spanToTrace.get(span)!())
2154
- }
2155
- span.end(timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0, exit)
2156
- }))
2160
+ return core.onExit(evaluate(span), (exit) => endSpan(span, exit, clock, timingEnabled))
2157
2161
  })
2158
2162
  }
2159
2163
 
@@ -1085,13 +1085,13 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
1085
1085
  return resume(core.exitSucceed(result.right))
1086
1086
  }
1087
1087
  switch (result.left._tag) {
1088
- case "Aborted": {
1088
+ case "Interrupt": {
1089
1089
  return resume(core.exitFailCause(internalCause.interrupt(FiberId.none)))
1090
1090
  }
1091
- case "Expected": {
1091
+ case "Fail": {
1092
1092
  return resume(core.fail(result.left.error))
1093
1093
  }
1094
- case "Unexpected": {
1094
+ case "Die": {
1095
1095
  return resume(core.die(result.left.defect))
1096
1096
  }
1097
1097
  }
@@ -3666,13 +3666,7 @@ export const makeSpanScoped = (
3666
3666
  const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
3667
3667
  const clock_ = Context.get(fiber.getFiberRef(defaultServices.currentServices), clock.clockTag)
3668
3668
  return core.as(
3669
- core.scopeAddFinalizerExit(scope, (exit) =>
3670
- core.sync(() => {
3671
- if (span.status._tag === "Ended") {
3672
- return
3673
- }
3674
- span.end(timingEnabled ? clock_.unsafeCurrentTimeNanos() : BigInt(0), exit)
3675
- })),
3669
+ core.scopeAddFinalizerExit(scope, (exit) => internalEffect.endSpan(span, exit, clock_, timingEnabled)),
3676
3670
  span
3677
3671
  )
3678
3672
  })
@@ -234,6 +234,9 @@ class BoundedPubSubArb<in out A> implements AtomicPubSub<A> {
234
234
  }
235
235
 
236
236
  publishAll(elements: Iterable<A>): Chunk.Chunk<A> {
237
+ if (this.subscriberCount === 0) {
238
+ return Chunk.empty()
239
+ }
237
240
  const chunk = Chunk.fromIterable(elements)
238
241
  const n = chunk.length
239
242
  const size = this.publisherIndex - this.subscribersIndex
@@ -400,6 +403,9 @@ class BoundedPubSubPow2<in out A> implements AtomicPubSub<A> {
400
403
  }
401
404
 
402
405
  publishAll(elements: Iterable<A>): Chunk.Chunk<A> {
406
+ if (this.subscriberCount === 0) {
407
+ return Chunk.empty()
408
+ }
403
409
  const chunk = Chunk.fromIterable(elements)
404
410
  const n = chunk.length
405
411
  const size = this.publisherIndex - this.subscribersIndex
@@ -560,6 +566,9 @@ class BoundedPubSubSingle<in out A> implements AtomicPubSub<A> {
560
566
  }
561
567
 
562
568
  publishAll(elements: Iterable<A>): Chunk.Chunk<A> {
569
+ if (this.subscriberCount === 0) {
570
+ return Chunk.empty()
571
+ }
563
572
  const chunk = Chunk.fromIterable(elements)
564
573
  if (Chunk.isEmpty(chunk)) {
565
574
  return chunk
@@ -692,8 +701,10 @@ class UnboundedPubSub<in out A> implements AtomicPubSub<A> {
692
701
  }
693
702
 
694
703
  publishAll(elements: Iterable<A>): Chunk.Chunk<A> {
695
- for (const a of elements) {
696
- this.publish(a)
704
+ if (this.publisherTail.subscribers !== 0) {
705
+ for (const a of elements) {
706
+ this.publish(a)
707
+ }
697
708
  }
698
709
  return Chunk.empty()
699
710
  }
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.4.5"
1
+ let moduleVersion = "3.4.7"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4