effect 2.4.14 → 2.4.16

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.
@@ -1,6 +1,7 @@
1
1
  import * as Chunk from "../Chunk.js"
2
2
  import type * as Config from "../Config.js"
3
3
  import * as ConfigError from "../ConfigError.js"
4
+ import * as Duration from "../Duration.js"
4
5
  import * as Either from "../Either.js"
5
6
  import type { LazyArg } from "../Function.js"
6
7
  import { constTrue, dual, pipe } from "../Function.js"
@@ -288,6 +289,15 @@ export const logLevel = (name?: string): Config.Config<LogLevel.LogLevel> => {
288
289
  return name === undefined ? config : nested(config, name)
289
290
  }
290
291
 
292
+ /** @internal */
293
+ export const duration = (name?: string): Config.Config<Duration.Duration> => {
294
+ const config = mapOrFail(string(), (value) => {
295
+ const duration = Duration.decodeUnknown(value)
296
+ return Either.fromOption(duration, () => configError.InvalidData([], `Expected a duration but received ${value}`))
297
+ })
298
+ return name === undefined ? config : nested(config, name)
299
+ }
300
+
291
301
  /** @internal */
292
302
  export const map = dual<
293
303
  <A, B>(f: (a: A) => B) => (self: Config.Config<A>) => Config.Config<B>,
@@ -779,7 +779,7 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
779
779
  if (exit._tag === "Failure") {
780
780
  const level = this.getFiberRef(core.currentUnhandledErrorLogLevel)
781
781
  if (!internalCause.isInterruptedOnly(exit.cause) && level._tag === "Some") {
782
- this.log("Fiber terminated with a non handled error", exit.cause, level)
782
+ this.log("Fiber terminated with an unhandled error", exit.cause, level)
783
783
  }
784
784
  }
785
785
  }
@@ -2028,7 +2028,7 @@ export const forEachConcurrentDiscard = <A, X, E, R>(
2028
2028
  }
2029
2029
  return exits
2030
2030
  }
2031
- const runFiber = <A, E, R>(eff: Effect.Effect<A, E, R>) => {
2031
+ const runFiber = <A, E, R>(eff: Effect.Effect<A, E, R>, interruptImmediately = false) => {
2032
2032
  const runnable = core.uninterruptible(graft(eff))
2033
2033
  const fiber = unsafeForkUnstarted(
2034
2034
  runnable,
@@ -2037,6 +2037,9 @@ export const forEachConcurrentDiscard = <A, X, E, R>(
2037
2037
  fiberScope.globalScope
2038
2038
  )
2039
2039
  parent._scheduler.scheduleTask(() => {
2040
+ if (interruptImmediately) {
2041
+ fiber.unsafeInterruptAsFork(parent.id())
2042
+ }
2040
2043
  fiber.resume(runnable)
2041
2044
  }, 0)
2042
2045
  return fiber
@@ -2142,26 +2145,44 @@ export const forEachConcurrentDiscard = <A, X, E, R>(
2142
2145
  }
2143
2146
  })
2144
2147
  )
2145
- return core.asUnit(core.tap(
2146
- core.flatten(core.onInterrupt(
2147
- restore(internalFiber.join(processingFiber)),
2148
- () => {
2149
- onInterruptSignal()
2150
- const all = [processingFiber] as Array<FiberRuntime<any, any>>
2151
- residual.map((blocked) => {
2152
- const fiber = runFiber(blocked)
2153
- parent._scheduler.scheduleTask(() => {
2154
- fiber.unsafeInterruptAsFork(parent.id())
2155
- }, 0)
2156
- return fiber
2157
- }).forEach((additional) => {
2158
- all.push(additional as unknown as FiberRuntime<any, any>)
2159
- })
2160
- return core.exit(fiberJoinAll(all))
2161
- }
2162
- )),
2163
- () => core.forEachSequential(joinOrder, (f) => f.inheritAll)
2164
- ))
2148
+ return core.asUnit(
2149
+ core.onExit(
2150
+ core.flatten(restore(internalFiber.join(processingFiber))),
2151
+ core.exitMatch({
2152
+ onFailure: () => {
2153
+ onInterruptSignal()
2154
+ const target = residual.length + 1
2155
+ const concurrency = Math.min(typeof n === "number" ? n : residual.length, residual.length)
2156
+ const toPop = Array.from(residual)
2157
+ return core.async<any, any>((cb) => {
2158
+ const exits: Array<Exit.Exit<any, any>> = []
2159
+ let count = 0
2160
+ let index = 0
2161
+ const check = (index: number, hitNext: boolean) => (exit: Exit.Exit<any, any>) => {
2162
+ exits[index] = exit
2163
+ count++
2164
+ if (count === target) {
2165
+ cb(Option.getOrThrow(core.exitCollectAll(exits, { parallel: true })))
2166
+ }
2167
+ if (toPop.length > 0 && hitNext) {
2168
+ next()
2169
+ }
2170
+ }
2171
+ const next = () => {
2172
+ runFiber(toPop.pop()!, true).addObserver(check(index, true))
2173
+ index++
2174
+ }
2175
+ processingFiber.addObserver(check(index, false))
2176
+ index++
2177
+ for (let i = 0; i < concurrency; i++) {
2178
+ next()
2179
+ }
2180
+ }) as any
2181
+ },
2182
+ onSuccess: () => core.forEachSequential(joinOrder, (f) => f.inheritAll)
2183
+ })
2184
+ )
2185
+ )
2165
2186
  })
2166
2187
  )
2167
2188
  )
@@ -21,8 +21,8 @@ export const tracerTag = Context.GenericTag<Tracer.Tracer>("effect/Tracer")
21
21
  /** @internal */
22
22
  export const spanTag = Context.GenericTag<Tracer.ParentSpan>("effect/ParentSpan")
23
23
 
24
- const randomString = (function() {
25
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
24
+ const randomHexString = (function() {
25
+ const characters = "abcdef0123456789"
26
26
  const charactersLength = characters.length
27
27
  return function(length: number) {
28
28
  let result = ""
@@ -56,7 +56,8 @@ export class NativeSpan implements Tracer.Span {
56
56
  startTime
57
57
  }
58
58
  this.attributes = new Map()
59
- this.spanId = `span${randomString(16)}`
59
+ this.traceId = parent._tag === "Some" ? parent.value.traceId : randomHexString(32)
60
+ this.spanId = randomHexString(16)
60
61
  }
61
62
 
62
63
  end(endTime: bigint, exit: Exit.Exit<unknown, unknown>): void {
@@ -1,4 +1,4 @@
1
- let moduleVersion = "2.4.14"
1
+ let moduleVersion = "2.4.16"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4