effect 2.4.18 → 2.4.19
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/Readable/package.json +6 -0
- package/RegExp/package.json +6 -0
- package/Subscribable/package.json +6 -0
- package/dist/cjs/Duration.js +39 -2
- package/dist/cjs/Duration.js.map +1 -1
- package/dist/cjs/List.js +5 -4
- package/dist/cjs/List.js.map +1 -1
- package/dist/cjs/Readable.js +79 -0
- package/dist/cjs/Readable.js.map +1 -0
- package/dist/cjs/RegExp.js +24 -0
- package/dist/cjs/RegExp.js.map +1 -0
- package/dist/cjs/Subscribable.js +91 -0
- package/dist/cjs/Subscribable.js.map +1 -0
- package/dist/cjs/SubscriptionRef.js.map +1 -1
- package/dist/cjs/TestAnnotation.js +2 -1
- package/dist/cjs/TestAnnotation.js.map +1 -1
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/cause.js +3 -2
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/configProvider.js +2 -2
- package/dist/cjs/internal/configProvider.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +28 -14
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/core.js +16 -85
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/effect/circular.js +5 -0
- package/dist/cjs/internal/effect/circular.js.map +1 -1
- package/dist/cjs/internal/errors.js +13 -0
- package/dist/cjs/internal/errors.js.map +1 -0
- package/dist/cjs/internal/fiberRuntime.js +79 -39
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/hashMap.js +1 -1
- package/dist/cjs/internal/hashMap.js.map +1 -1
- package/dist/cjs/internal/matcher.js +5 -4
- package/dist/cjs/internal/matcher.js.map +1 -1
- package/dist/cjs/internal/ref.js +6 -1
- package/dist/cjs/internal/ref.js.map +1 -1
- package/dist/cjs/internal/schedule/intervals.js +2 -1
- package/dist/cjs/internal/schedule/intervals.js.map +1 -1
- package/dist/cjs/internal/subscriptionRef.js +8 -0
- package/dist/cjs/internal/subscriptionRef.js.map +1 -1
- package/dist/cjs/internal/trie.js +1 -1
- package/dist/cjs/internal/trie.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Duration.d.ts +16 -0
- package/dist/dts/Duration.d.ts.map +1 -1
- package/dist/dts/List.d.ts.map +1 -1
- package/dist/dts/Readable.d.ts +55 -0
- package/dist/dts/Readable.d.ts.map +1 -0
- package/dist/dts/Ref.d.ts +2 -2
- package/dist/dts/Ref.d.ts.map +1 -1
- package/dist/dts/RegExp.d.ts +17 -0
- package/dist/dts/RegExp.d.ts.map +1 -0
- package/dist/dts/Subscribable.d.ts +59 -0
- package/dist/dts/Subscribable.d.ts.map +1 -0
- package/dist/dts/SubscriptionRef.d.ts +2 -2
- package/dist/dts/SubscriptionRef.d.ts.map +1 -1
- package/dist/dts/TestAnnotation.d.ts.map +1 -1
- package/dist/dts/index.d.ts +14 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/errors.d.ts +5 -0
- package/dist/dts/internal/errors.d.ts.map +1 -0
- package/dist/esm/Duration.js +38 -1
- package/dist/esm/Duration.js.map +1 -1
- package/dist/esm/List.js +4 -3
- package/dist/esm/List.js.map +1 -1
- package/dist/esm/Readable.js +45 -0
- package/dist/esm/Readable.js.map +1 -0
- package/dist/esm/RegExp.js +17 -0
- package/dist/esm/RegExp.js.map +1 -0
- package/dist/esm/Subscribable.js +56 -0
- package/dist/esm/Subscribable.js.map +1 -0
- package/dist/esm/SubscriptionRef.js.map +1 -1
- package/dist/esm/TestAnnotation.js +2 -1
- package/dist/esm/TestAnnotation.js.map +1 -1
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/cause.js +3 -2
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/configProvider.js +2 -2
- package/dist/esm/internal/configProvider.js.map +1 -1
- package/dist/esm/internal/core-effect.js +25 -12
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/core.js +13 -82
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/effect/circular.js +5 -0
- package/dist/esm/internal/effect/circular.js.map +1 -1
- package/dist/esm/internal/errors.js +6 -0
- package/dist/esm/internal/errors.js.map +1 -0
- package/dist/esm/internal/fiberRuntime.js +77 -36
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/hashMap.js +1 -1
- package/dist/esm/internal/hashMap.js.map +1 -1
- package/dist/esm/internal/matcher.js +4 -3
- package/dist/esm/internal/matcher.js.map +1 -1
- package/dist/esm/internal/ref.js +6 -1
- package/dist/esm/internal/ref.js.map +1 -1
- package/dist/esm/internal/schedule/intervals.js +2 -1
- package/dist/esm/internal/schedule/intervals.js.map +1 -1
- package/dist/esm/internal/subscriptionRef.js +8 -0
- package/dist/esm/internal/subscriptionRef.js.map +1 -1
- package/dist/esm/internal/trie.js +1 -1
- package/dist/esm/internal/trie.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +25 -1
- package/src/Duration.ts +54 -1
- package/src/List.ts +5 -3
- package/src/Readable.ts +92 -0
- package/src/Ref.ts +2 -2
- package/src/RegExp.ts +17 -0
- package/src/Subscribable.ts +99 -0
- package/src/SubscriptionRef.ts +2 -2
- package/src/TestAnnotation.ts +2 -1
- package/src/index.ts +17 -0
- package/src/internal/cause.ts +3 -2
- package/src/internal/configProvider.ts +2 -3
- package/src/internal/core-effect.ts +78 -66
- package/src/internal/core.ts +13 -150
- package/src/internal/effect/circular.ts +7 -1
- package/src/internal/errors.ts +7 -0
- package/src/internal/fiberRuntime.ts +120 -86
- package/src/internal/hashMap.ts +1 -1
- package/src/internal/matcher.ts +5 -3
- package/src/internal/ref.ts +8 -2
- package/src/internal/schedule/intervals.ts +2 -1
- package/src/internal/subscriptionRef.ts +8 -0
- package/src/internal/trie.ts +1 -1
- package/src/internal/version.ts +1 -1
package/src/Ref.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type * as Effect from "./Effect.js"
|
|
5
5
|
import * as internal from "./internal/ref.js"
|
|
6
6
|
import type * as Option from "./Option.js"
|
|
7
|
-
import type {
|
|
7
|
+
import type { Readable } from "./Readable.js"
|
|
8
8
|
import type * as Types from "./Types.js"
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -23,7 +23,7 @@ export type RefTypeId = typeof RefTypeId
|
|
|
23
23
|
* @since 2.0.0
|
|
24
24
|
* @category models
|
|
25
25
|
*/
|
|
26
|
-
export interface Ref<in out A> extends Ref.Variance<A>,
|
|
26
|
+
export interface Ref<in out A> extends Ref.Variance<A>, Readable<A> {
|
|
27
27
|
modify<B>(f: (a: A) => readonly [B, A]): Effect.Effect<B>
|
|
28
28
|
}
|
|
29
29
|
|
package/src/RegExp.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides utility functions for working with RegExp in TypeScript.
|
|
3
|
+
*
|
|
4
|
+
* @since 2.0.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Escapes special characters in a regular expression pattern.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import * as RegExp from "effect/RegExp"
|
|
12
|
+
*
|
|
13
|
+
* assert.deepStrictEqual(RegExp.escape("a*b"), "a\\*b")
|
|
14
|
+
*
|
|
15
|
+
* @since 2.0.0
|
|
16
|
+
*/
|
|
17
|
+
export const escape = (string: string): string => string.replace(/[/\\^$*+?.()|[\]{}]/g, "\\$&")
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 2.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Effect from "./Effect.js"
|
|
5
|
+
import { dual } from "./Function.js"
|
|
6
|
+
import { pipeArguments } from "./Pipeable.js"
|
|
7
|
+
import { hasProperty } from "./Predicate.js"
|
|
8
|
+
import * as Readable from "./Readable.js"
|
|
9
|
+
import * as Stream from "./Stream.js"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @since 2.0.0
|
|
13
|
+
* @category type ids
|
|
14
|
+
*/
|
|
15
|
+
export const TypeId = Symbol.for("effect/Subscribable")
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @since 2.0.0
|
|
19
|
+
* @category type ids
|
|
20
|
+
*/
|
|
21
|
+
export type TypeId = typeof TypeId
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @since 2.0.0
|
|
25
|
+
* @category models
|
|
26
|
+
*/
|
|
27
|
+
export interface Subscribable<A, E = never, R = never> extends Readable.Readable<A, E, R> {
|
|
28
|
+
readonly [TypeId]: TypeId
|
|
29
|
+
readonly changes: Stream.Stream<A, E, R>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @since 2.0.0
|
|
34
|
+
* @category refinements
|
|
35
|
+
*/
|
|
36
|
+
export const isSubscribable = (u: unknown): u is Subscribable<unknown, unknown, unknown> => hasProperty(u, TypeId)
|
|
37
|
+
|
|
38
|
+
const Proto: Omit<Subscribable<any>, "get" | "changes"> = {
|
|
39
|
+
[Readable.TypeId]: Readable.TypeId,
|
|
40
|
+
[TypeId]: TypeId,
|
|
41
|
+
pipe() {
|
|
42
|
+
return pipeArguments(this, arguments)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @since 2.0.0
|
|
48
|
+
* @category constructors
|
|
49
|
+
*/
|
|
50
|
+
export const make = <A, E, R>(options: {
|
|
51
|
+
readonly get: Effect.Effect<A, E, R>
|
|
52
|
+
readonly changes: Stream.Stream<A, E, R>
|
|
53
|
+
}): Subscribable<A, E, R> => Object.assign(Object.create(Proto), options)
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @since 2.0.0
|
|
57
|
+
* @category combinators
|
|
58
|
+
*/
|
|
59
|
+
export const map: {
|
|
60
|
+
<A, B>(f: (a: NoInfer<A>) => B): <E, R>(fa: Subscribable<A, E, R>) => Subscribable<B, E, R>
|
|
61
|
+
<A, E, R, B>(self: Subscribable<A, E, R>, f: (a: NoInfer<A>) => B): Subscribable<B, E, R>
|
|
62
|
+
} = dual(2, <A, E, R, B>(self: Subscribable<A, E, R>, f: (a: NoInfer<A>) => B): Subscribable<B, E, R> =>
|
|
63
|
+
make({
|
|
64
|
+
get: Effect.map(self.get, f),
|
|
65
|
+
changes: Stream.map(self.changes, f)
|
|
66
|
+
}))
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @since 2.0.0
|
|
70
|
+
* @category combinators
|
|
71
|
+
*/
|
|
72
|
+
export const mapEffect: {
|
|
73
|
+
<A, B, E2, R2>(
|
|
74
|
+
f: (a: NoInfer<A>) => Effect.Effect<B, E2, R2>
|
|
75
|
+
): <E, R>(fa: Subscribable<A, E, R>) => Subscribable<B, E | E2, R | R2>
|
|
76
|
+
<A, E, R, B, E2, R2>(
|
|
77
|
+
self: Subscribable<A, E, R>,
|
|
78
|
+
f: (a: NoInfer<A>) => Effect.Effect<B, E2, R2>
|
|
79
|
+
): Subscribable<B, E | E2, R | R2>
|
|
80
|
+
} = dual(2, <A, E, R, B, E2, R2>(
|
|
81
|
+
self: Subscribable<A, E, R>,
|
|
82
|
+
f: (a: NoInfer<A>) => Effect.Effect<B, E2, R2>
|
|
83
|
+
): Subscribable<B, E | E2, R | R2> =>
|
|
84
|
+
make({
|
|
85
|
+
get: Effect.flatMap(self.get, f),
|
|
86
|
+
changes: Stream.mapEffect(self.changes, f)
|
|
87
|
+
}))
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @since 2.0.0
|
|
91
|
+
* @category constructors
|
|
92
|
+
*/
|
|
93
|
+
export const unwrap = <A, E, R, E1, R1>(
|
|
94
|
+
effect: Effect.Effect<Subscribable<A, E, R>, E1, R1>
|
|
95
|
+
): Subscribable<A, E | E1, R | R1> =>
|
|
96
|
+
make({
|
|
97
|
+
get: Effect.flatMap(effect, (s) => s.get),
|
|
98
|
+
changes: Stream.unwrap(Effect.map(effect, (s) => s.changes))
|
|
99
|
+
})
|
package/src/SubscriptionRef.ts
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
import type * as Effect from "./Effect.js"
|
|
5
5
|
import * as internal from "./internal/subscriptionRef.js"
|
|
6
6
|
import type * as Option from "./Option.js"
|
|
7
|
-
import type { Pipeable } from "./Pipeable.js"
|
|
8
7
|
import type * as PubSub from "./PubSub.js"
|
|
9
8
|
import * as Ref from "./Ref.js"
|
|
10
9
|
import type * as Stream from "./Stream.js"
|
|
10
|
+
import type { Subscribable } from "./Subscribable.js"
|
|
11
11
|
import * as Synchronized from "./SynchronizedRef.js"
|
|
12
12
|
import type * as Types from "./Types.js"
|
|
13
13
|
|
|
@@ -31,7 +31,7 @@ export type SubscriptionRefTypeId = typeof SubscriptionRefTypeId
|
|
|
31
31
|
* @category models
|
|
32
32
|
*/
|
|
33
33
|
export interface SubscriptionRef<in out A>
|
|
34
|
-
extends SubscriptionRef.Variance<A>, Synchronized.SynchronizedRef<A>,
|
|
34
|
+
extends SubscriptionRef.Variance<A>, Synchronized.SynchronizedRef<A>, Subscribable<A>
|
|
35
35
|
{
|
|
36
36
|
/** @internal */
|
|
37
37
|
readonly ref: Ref.Ref<A>
|
package/src/TestAnnotation.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type * as Fiber from "./Fiber.js"
|
|
|
8
8
|
import { pipe } from "./Function.js"
|
|
9
9
|
import * as Hash from "./Hash.js"
|
|
10
10
|
import * as HashSet from "./HashSet.js"
|
|
11
|
+
import { getBugErrorMessage } from "./internal/errors.js"
|
|
11
12
|
import type * as MutableRef from "./MutableRef.js"
|
|
12
13
|
import { hasProperty } from "./Predicate.js"
|
|
13
14
|
import type * as SortedSet from "./SortedSet.js"
|
|
@@ -96,7 +97,7 @@ export const compose = <A>(
|
|
|
96
97
|
if (Either.isLeft(left) && Either.isRight(right)) {
|
|
97
98
|
return right
|
|
98
99
|
}
|
|
99
|
-
throw new Error("
|
|
100
|
+
throw new Error(getBugErrorMessage("TestAnnotation.compose"))
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
/**
|
package/src/index.ts
CHANGED
|
@@ -570,6 +570,11 @@ export * as Random from "./Random.js"
|
|
|
570
570
|
*/
|
|
571
571
|
export * as RateLimiter from "./RateLimiter.js"
|
|
572
572
|
|
|
573
|
+
/**
|
|
574
|
+
* @since 2.0.0
|
|
575
|
+
*/
|
|
576
|
+
export * as Readable from "./Readable.js"
|
|
577
|
+
|
|
573
578
|
/**
|
|
574
579
|
* This module provides utility functions for working with arrays in TypeScript.
|
|
575
580
|
*
|
|
@@ -594,6 +599,13 @@ export * as RedBlackTree from "./RedBlackTree.js"
|
|
|
594
599
|
*/
|
|
595
600
|
export * as Ref from "./Ref.js"
|
|
596
601
|
|
|
602
|
+
/**
|
|
603
|
+
* This module provides utility functions for working with RegExp in TypeScript.
|
|
604
|
+
*
|
|
605
|
+
* @since 2.0.0
|
|
606
|
+
*/
|
|
607
|
+
export * as RegExp from "./RegExp.js"
|
|
608
|
+
|
|
597
609
|
/**
|
|
598
610
|
* @since 2.0.0
|
|
599
611
|
*/
|
|
@@ -740,6 +752,11 @@ export * as String from "./String.js"
|
|
|
740
752
|
*/
|
|
741
753
|
export * as Struct from "./Struct.js"
|
|
742
754
|
|
|
755
|
+
/**
|
|
756
|
+
* @since 2.0.0
|
|
757
|
+
*/
|
|
758
|
+
export * as Subscribable from "./Subscribable.js"
|
|
759
|
+
|
|
743
760
|
/**
|
|
744
761
|
* @since 2.0.0
|
|
745
762
|
*/
|
package/src/internal/cause.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { Predicate, Refinement } from "../Predicate.js"
|
|
|
14
14
|
import * as ReadonlyArray from "../ReadonlyArray.js"
|
|
15
15
|
import type { ParentSpan, Span } from "../Tracer.js"
|
|
16
16
|
import type { NoInfer } from "../Types.js"
|
|
17
|
+
import { getBugErrorMessage } from "./errors.js"
|
|
17
18
|
import * as OpCodes from "./opCodes/cause.js"
|
|
18
19
|
|
|
19
20
|
// -----------------------------------------------------------------------------
|
|
@@ -604,7 +605,7 @@ const flattenCauseLoop = (
|
|
|
604
605
|
causes = sequential
|
|
605
606
|
flattened = updated
|
|
606
607
|
}
|
|
607
|
-
throw new Error("
|
|
608
|
+
throw new Error(getBugErrorMessage("Cause.flattenCauseLoop"))
|
|
608
609
|
}
|
|
609
610
|
|
|
610
611
|
// -----------------------------------------------------------------------------
|
|
@@ -740,7 +741,7 @@ const evaluateCause = (
|
|
|
740
741
|
}
|
|
741
742
|
}
|
|
742
743
|
}
|
|
743
|
-
throw new Error("
|
|
744
|
+
throw new Error(getBugErrorMessage("Cause.evaluateCauseLoop"))
|
|
744
745
|
}
|
|
745
746
|
|
|
746
747
|
// -----------------------------------------------------------------------------
|
|
@@ -13,6 +13,7 @@ import * as number from "../Number.js"
|
|
|
13
13
|
import * as Option from "../Option.js"
|
|
14
14
|
import { pipeArguments } from "../Pipeable.js"
|
|
15
15
|
import * as ReadonlyArray from "../ReadonlyArray.js"
|
|
16
|
+
import * as regexp from "../RegExp.js"
|
|
16
17
|
import type * as _config from "./config.js"
|
|
17
18
|
import * as configError from "./configError.js"
|
|
18
19
|
import * as pathPatch from "./configProvider/pathPatch.js"
|
|
@@ -595,7 +596,7 @@ export const within = dual<
|
|
|
595
596
|
})
|
|
596
597
|
|
|
597
598
|
const splitPathString = (text: string, delim: string): ReadonlyArray<string> => {
|
|
598
|
-
const split = text.split(new RegExp(`\\s*${
|
|
599
|
+
const split = text.split(new RegExp(`\\s*${regexp.escape(delim)}\\s*`))
|
|
599
600
|
return split
|
|
600
601
|
}
|
|
601
602
|
|
|
@@ -626,8 +627,6 @@ const transpose = <A>(array: ReadonlyArray<ReadonlyArray<A>>): ReadonlyArray<Rea
|
|
|
626
627
|
return Object.keys(array[0]).map((column) => array.map((row) => row[column as any]))
|
|
627
628
|
}
|
|
628
629
|
|
|
629
|
-
const escapeRegex = (string: string): string => string.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&")
|
|
630
|
-
|
|
631
630
|
const indicesFrom = (quotedIndices: HashSet.HashSet<string>): Effect.Effect<ReadonlyArray<number>> =>
|
|
632
631
|
pipe(
|
|
633
632
|
core.forEachSequential(quotedIndices, parseQuotedIndex),
|
|
@@ -27,9 +27,11 @@ import type * as runtimeFlagsPatch from "../RuntimeFlagsPatch.js"
|
|
|
27
27
|
import * as Tracer from "../Tracer.js"
|
|
28
28
|
import type { MergeRecord, NoInfer } from "../Types.js"
|
|
29
29
|
import * as internalCause from "./cause.js"
|
|
30
|
+
import { clockTag } from "./clock.js"
|
|
30
31
|
import * as core from "./core.js"
|
|
31
32
|
import * as defaultServices from "./defaultServices.js"
|
|
32
33
|
import * as fiberRefsPatch from "./fiberRefs/patch.js"
|
|
34
|
+
import type { FiberRuntime } from "./fiberRuntime.js"
|
|
33
35
|
import * as metricLabel from "./metric/label.js"
|
|
34
36
|
import * as runtimeFlags from "./runtimeFlags.js"
|
|
35
37
|
import * as SingleShotGen from "./singleShotGen.js"
|
|
@@ -1072,8 +1074,9 @@ export const mapAccum: {
|
|
|
1072
1074
|
let i = 0
|
|
1073
1075
|
while (!(next = iterator.next()).done) {
|
|
1074
1076
|
const index = i++
|
|
1077
|
+
const value = next.value
|
|
1075
1078
|
result = core.flatMap(result, (state) =>
|
|
1076
|
-
core.map(f(state,
|
|
1079
|
+
core.map(f(state, value, index), ([z, b]) => {
|
|
1077
1080
|
builder.push(b)
|
|
1078
1081
|
return z
|
|
1079
1082
|
}))
|
|
@@ -2006,13 +2009,6 @@ export const currentSpan: Effect.Effect<Tracer.Span, Cause.NoSuchElementExceptio
|
|
|
2006
2009
|
}
|
|
2007
2010
|
)
|
|
2008
2011
|
|
|
2009
|
-
const bigint0 = BigInt(0)
|
|
2010
|
-
/** @internal */
|
|
2011
|
-
export const currentTimeNanosTracing = core.fiberRefGetWith(
|
|
2012
|
-
core.currentTracerTimingEnabled,
|
|
2013
|
-
(enabled) => enabled ? Clock.currentTimeNanos : core.succeed(bigint0)
|
|
2014
|
-
)
|
|
2015
|
-
|
|
2016
2012
|
/* @internal */
|
|
2017
2013
|
export const linkSpans = dual<
|
|
2018
2014
|
(
|
|
@@ -2040,8 +2036,11 @@ export const linkSpans = dual<
|
|
|
2040
2036
|
)
|
|
2041
2037
|
)
|
|
2042
2038
|
|
|
2039
|
+
const bigint0 = BigInt(0)
|
|
2040
|
+
|
|
2043
2041
|
/** @internal */
|
|
2044
|
-
export const
|
|
2042
|
+
export const unsafeMakeSpan = <XA, XE>(
|
|
2043
|
+
fiber: FiberRuntime<XA, XE>,
|
|
2045
2044
|
name: string,
|
|
2046
2045
|
options?: {
|
|
2047
2046
|
readonly attributes?: Record<string, unknown> | undefined
|
|
@@ -2050,55 +2049,67 @@ export const makeSpan = (
|
|
|
2050
2049
|
readonly root?: boolean | undefined
|
|
2051
2050
|
readonly context?: Context.Context<never> | undefined
|
|
2052
2051
|
}
|
|
2053
|
-
)
|
|
2054
|
-
core.
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
return core.noopSpan(name)
|
|
2059
|
-
}
|
|
2052
|
+
) => {
|
|
2053
|
+
const enabled = fiber.getFiberRef(core.currentTracerEnabled)
|
|
2054
|
+
if (enabled === false) {
|
|
2055
|
+
return core.noopSpan(name)
|
|
2056
|
+
}
|
|
2060
2057
|
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2058
|
+
const context = fiber.getFiberRef(core.currentContext)
|
|
2059
|
+
const services = fiber.getFiberRef(defaultServices.currentServices)
|
|
2060
|
+
|
|
2061
|
+
const tracer = Context.get(services, internalTracer.tracerTag)
|
|
2062
|
+
const clock = Context.get(services, Clock.Clock)
|
|
2063
|
+
const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
|
|
2064
|
+
|
|
2065
|
+
const fiberRefs = fiber.getFiberRefs()
|
|
2066
|
+
const annotationsFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanAnnotations)
|
|
2067
|
+
const linksFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanLinks)
|
|
2068
|
+
|
|
2069
|
+
const parent = options?.parent
|
|
2070
|
+
? Option.some(options.parent)
|
|
2071
|
+
: options?.root
|
|
2072
|
+
? Option.none()
|
|
2073
|
+
: Context.getOption(context, internalTracer.spanTag)
|
|
2074
|
+
|
|
2075
|
+
const links = linksFromEnv._tag === "Some" ?
|
|
2076
|
+
options?.links !== undefined ?
|
|
2077
|
+
[
|
|
2078
|
+
...Chunk.toReadonlyArray(linksFromEnv.value),
|
|
2079
|
+
...(options?.links ?? [])
|
|
2080
|
+
] :
|
|
2081
|
+
Chunk.toReadonlyArray(linksFromEnv.value) :
|
|
2082
|
+
options?.links ?? ReadonlyArray.empty()
|
|
2083
|
+
|
|
2084
|
+
const span = tracer.span(
|
|
2085
|
+
name,
|
|
2086
|
+
parent,
|
|
2087
|
+
options?.context ?? Context.empty(),
|
|
2088
|
+
links,
|
|
2089
|
+
timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0
|
|
2090
|
+
)
|
|
2092
2091
|
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2092
|
+
if (annotationsFromEnv._tag === "Some") {
|
|
2093
|
+
HashMap.forEach(annotationsFromEnv.value, (value, key) => span.attribute(key, value))
|
|
2094
|
+
}
|
|
2095
|
+
if (options?.attributes !== undefined) {
|
|
2096
|
+
Object.entries(options.attributes).forEach(([k, v]) => span.attribute(k, v))
|
|
2097
|
+
}
|
|
2099
2098
|
|
|
2100
|
-
|
|
2101
|
-
|
|
2099
|
+
return span
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
/** @internal */
|
|
2103
|
+
export const makeSpan = (
|
|
2104
|
+
name: string,
|
|
2105
|
+
options?: {
|
|
2106
|
+
readonly attributes?: Record<string, unknown> | undefined
|
|
2107
|
+
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
|
|
2108
|
+
readonly parent?: Tracer.ParentSpan | undefined
|
|
2109
|
+
readonly root?: boolean | undefined
|
|
2110
|
+
readonly context?: Context.Context<never> | undefined
|
|
2111
|
+
}
|
|
2112
|
+
): Effect.Effect<Tracer.Span> => core.withFiberRuntime((fiber) => core.succeed(unsafeMakeSpan(fiber, name, options)))
|
|
2102
2113
|
|
|
2103
2114
|
/* @internal */
|
|
2104
2115
|
export const spanAnnotations: Effect.Effect<HashMap.HashMap<string, unknown>> = core
|
|
@@ -2134,17 +2145,18 @@ export const useSpan: {
|
|
|
2134
2145
|
} | undefined = args.length === 1 ? undefined : args[0]
|
|
2135
2146
|
const evaluate: (span: Tracer.Span) => Effect.Effect<A, E, R> = args[args.length - 1]
|
|
2136
2147
|
|
|
2137
|
-
return core.
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
(
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
)
|
|
2147
|
-
|
|
2148
|
+
return core.withFiberRuntime<A, E, R>((fiber) => {
|
|
2149
|
+
const span = unsafeMakeSpan(fiber, name, options)
|
|
2150
|
+
const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
|
|
2151
|
+
const clock = Context.get(fiber.getFiberRef(defaultServices.currentServices), clockTag)
|
|
2152
|
+
return core.onExit(evaluate(span), (exit) =>
|
|
2153
|
+
core.sync(() => {
|
|
2154
|
+
if (span.status._tag === "Ended") {
|
|
2155
|
+
return
|
|
2156
|
+
}
|
|
2157
|
+
span.end(timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0, exit)
|
|
2158
|
+
}))
|
|
2159
|
+
})
|
|
2148
2160
|
}
|
|
2149
2161
|
|
|
2150
2162
|
/** @internal */
|
package/src/internal/core.ts
CHANGED
|
@@ -41,6 +41,7 @@ import * as internalCause from "./cause.js"
|
|
|
41
41
|
import * as deferred from "./deferred.js"
|
|
42
42
|
import * as internalDiffer from "./differ.js"
|
|
43
43
|
import { effectVariance, StructuralCommitPrototype } from "./effectable.js"
|
|
44
|
+
import { getBugErrorMessage } from "./errors.js"
|
|
44
45
|
import type * as FiberRuntime from "./fiberRuntime.js"
|
|
45
46
|
import type * as fiberScope from "./fiberScope.js"
|
|
46
47
|
import * as DeferredOpCodes from "./opCodes/deferred.js"
|
|
@@ -469,7 +470,7 @@ export const custom: {
|
|
|
469
470
|
break
|
|
470
471
|
}
|
|
471
472
|
default: {
|
|
472
|
-
throw new Error("
|
|
473
|
+
throw new Error(getBugErrorMessage("you're not supposed to end up here"))
|
|
473
474
|
}
|
|
474
475
|
}
|
|
475
476
|
return wrapper
|
|
@@ -2086,143 +2087,6 @@ export const scopeFork = (
|
|
|
2086
2087
|
strategy: ExecutionStrategy.ExecutionStrategy
|
|
2087
2088
|
): Effect.Effect<Scope.Scope.Closeable> => self.fork(strategy)
|
|
2088
2089
|
|
|
2089
|
-
// -----------------------------------------------------------------------------
|
|
2090
|
-
// ReleaseMap
|
|
2091
|
-
// -----------------------------------------------------------------------------
|
|
2092
|
-
|
|
2093
|
-
/** @internal */
|
|
2094
|
-
export type ReleaseMapState = {
|
|
2095
|
-
_tag: "Exited"
|
|
2096
|
-
nextKey: number
|
|
2097
|
-
exit: Exit.Exit<unknown, unknown>
|
|
2098
|
-
update: (finalizer: Scope.Scope.Finalizer) => Scope.Scope.Finalizer
|
|
2099
|
-
} | {
|
|
2100
|
-
_tag: "Running"
|
|
2101
|
-
nextKey: number
|
|
2102
|
-
finalizers: Map<number, Scope.Scope.Finalizer>
|
|
2103
|
-
update: (finalizer: Scope.Scope.Finalizer) => Scope.Scope.Finalizer
|
|
2104
|
-
}
|
|
2105
|
-
|
|
2106
|
-
/** @internal */
|
|
2107
|
-
export interface ReleaseMap {
|
|
2108
|
-
state: ReleaseMapState // mutable by design
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
|
-
/* @internal */
|
|
2112
|
-
export const releaseMapAdd = dual<
|
|
2113
|
-
(finalizer: Scope.Scope.Finalizer) => (self: ReleaseMap) => Effect.Effect<Scope.Scope.Finalizer>,
|
|
2114
|
-
(self: ReleaseMap, finalizer: Scope.Scope.Finalizer) => Effect.Effect<Scope.Scope.Finalizer>
|
|
2115
|
-
>(2, (self, finalizer) =>
|
|
2116
|
-
map(
|
|
2117
|
-
releaseMapAddIfOpen(self, finalizer),
|
|
2118
|
-
Option.match({
|
|
2119
|
-
onNone: (): Scope.Scope.Finalizer => () => unit,
|
|
2120
|
-
onSome: (key): Scope.Scope.Finalizer => (exit) => releaseMapRelease(key, exit)(self)
|
|
2121
|
-
})
|
|
2122
|
-
))
|
|
2123
|
-
|
|
2124
|
-
/* @internal */
|
|
2125
|
-
export const releaseMapRelease = dual<
|
|
2126
|
-
(key: number, exit: Exit.Exit<unknown, unknown>) => (self: ReleaseMap) => Effect.Effect<void>,
|
|
2127
|
-
(self: ReleaseMap, key: number, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void>
|
|
2128
|
-
>(3, (self, key, exit) =>
|
|
2129
|
-
suspend(() => {
|
|
2130
|
-
switch (self.state._tag) {
|
|
2131
|
-
case "Exited": {
|
|
2132
|
-
return unit
|
|
2133
|
-
}
|
|
2134
|
-
case "Running": {
|
|
2135
|
-
const finalizer = self.state.finalizers.get(key)
|
|
2136
|
-
self.state.finalizers.delete(key)
|
|
2137
|
-
if (finalizer != null) {
|
|
2138
|
-
return self.state.update(finalizer)(exit)
|
|
2139
|
-
}
|
|
2140
|
-
return unit
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
}))
|
|
2144
|
-
|
|
2145
|
-
/* @internal */
|
|
2146
|
-
export const releaseMapAddIfOpen = dual<
|
|
2147
|
-
(finalizer: Scope.Scope.Finalizer) => (self: ReleaseMap) => Effect.Effect<Option.Option<number>>,
|
|
2148
|
-
(self: ReleaseMap, finalizer: Scope.Scope.Finalizer) => Effect.Effect<Option.Option<number>>
|
|
2149
|
-
>(2, (self, finalizer) =>
|
|
2150
|
-
suspend(() => {
|
|
2151
|
-
switch (self.state._tag) {
|
|
2152
|
-
case "Exited": {
|
|
2153
|
-
self.state.nextKey += 1
|
|
2154
|
-
return as(finalizer(self.state.exit), Option.none())
|
|
2155
|
-
}
|
|
2156
|
-
case "Running": {
|
|
2157
|
-
const key = self.state.nextKey
|
|
2158
|
-
self.state.finalizers.set(key, finalizer)
|
|
2159
|
-
self.state.nextKey += 1
|
|
2160
|
-
return succeed(Option.some(key))
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2163
|
-
}))
|
|
2164
|
-
|
|
2165
|
-
/* @internal */
|
|
2166
|
-
export const releaseMapGet = dual<
|
|
2167
|
-
(key: number) => (self: ReleaseMap) => Effect.Effect<Option.Option<Scope.Scope.Finalizer>>,
|
|
2168
|
-
(self: ReleaseMap, key: number) => Effect.Effect<Option.Option<Scope.Scope.Finalizer>>
|
|
2169
|
-
>(
|
|
2170
|
-
2,
|
|
2171
|
-
(self, key) =>
|
|
2172
|
-
sync((): Option.Option<Scope.Scope.Finalizer> =>
|
|
2173
|
-
self.state._tag === "Running" ? Option.fromNullable(self.state.finalizers.get(key)) : Option.none()
|
|
2174
|
-
)
|
|
2175
|
-
)
|
|
2176
|
-
|
|
2177
|
-
/* @internal */
|
|
2178
|
-
export const releaseMapReplace = dual<
|
|
2179
|
-
(
|
|
2180
|
-
key: number,
|
|
2181
|
-
finalizer: Scope.Scope.Finalizer
|
|
2182
|
-
) => (self: ReleaseMap) => Effect.Effect<Option.Option<Scope.Scope.Finalizer>>,
|
|
2183
|
-
(
|
|
2184
|
-
self: ReleaseMap,
|
|
2185
|
-
key: number,
|
|
2186
|
-
finalizer: Scope.Scope.Finalizer
|
|
2187
|
-
) => Effect.Effect<Option.Option<Scope.Scope.Finalizer>>
|
|
2188
|
-
>(3, (self, key, finalizer) =>
|
|
2189
|
-
suspend(() => {
|
|
2190
|
-
switch (self.state._tag) {
|
|
2191
|
-
case "Exited": {
|
|
2192
|
-
return as(finalizer(self.state.exit), Option.none())
|
|
2193
|
-
}
|
|
2194
|
-
case "Running": {
|
|
2195
|
-
const fin = Option.fromNullable(self.state.finalizers.get(key))
|
|
2196
|
-
self.state.finalizers.set(key, finalizer)
|
|
2197
|
-
return succeed(fin)
|
|
2198
|
-
}
|
|
2199
|
-
}
|
|
2200
|
-
}))
|
|
2201
|
-
|
|
2202
|
-
/* @internal */
|
|
2203
|
-
export const releaseMapRemove = dual<
|
|
2204
|
-
(key: number) => (self: ReleaseMap) => Effect.Effect<Option.Option<Scope.Scope.Finalizer>>,
|
|
2205
|
-
(self: ReleaseMap, key: number) => Effect.Effect<Option.Option<Scope.Scope.Finalizer>>
|
|
2206
|
-
>(2, (self, key) =>
|
|
2207
|
-
sync(() => {
|
|
2208
|
-
if (self.state._tag === "Exited") {
|
|
2209
|
-
return Option.none()
|
|
2210
|
-
}
|
|
2211
|
-
const fin = Option.fromNullable(self.state.finalizers.get(key))
|
|
2212
|
-
self.state.finalizers.delete(key)
|
|
2213
|
-
return fin
|
|
2214
|
-
}))
|
|
2215
|
-
|
|
2216
|
-
/* @internal */
|
|
2217
|
-
export const releaseMapMake: Effect.Effect<ReleaseMap> = sync((): ReleaseMap => ({
|
|
2218
|
-
state: {
|
|
2219
|
-
_tag: "Running",
|
|
2220
|
-
nextKey: 0,
|
|
2221
|
-
finalizers: new Map(),
|
|
2222
|
-
update: identity
|
|
2223
|
-
}
|
|
2224
|
-
}))
|
|
2225
|
-
|
|
2226
2090
|
// -----------------------------------------------------------------------------
|
|
2227
2091
|
// Cause
|
|
2228
2092
|
// -----------------------------------------------------------------------------
|
|
@@ -2877,10 +2741,8 @@ export const deferredAwait = <A, E>(self: Deferred.Deferred<A, E>): Effect.Effec
|
|
|
2877
2741
|
return resume(state.effect)
|
|
2878
2742
|
}
|
|
2879
2743
|
case DeferredOpCodes.OP_STATE_PENDING: {
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
MutableRef.set(deferred.pending([resume, ...state.joiners]))
|
|
2883
|
-
)
|
|
2744
|
+
// we can push here as the internal state is mutable
|
|
2745
|
+
state.joiners.push(resume)
|
|
2884
2746
|
return deferredInterruptJoiner(self, resume)
|
|
2885
2747
|
}
|
|
2886
2748
|
}
|
|
@@ -2908,8 +2770,8 @@ export const deferredCompleteWith = dual<
|
|
|
2908
2770
|
return false
|
|
2909
2771
|
}
|
|
2910
2772
|
case DeferredOpCodes.OP_STATE_PENDING: {
|
|
2911
|
-
|
|
2912
|
-
for (let i = 0
|
|
2773
|
+
MutableRef.set(self.state, deferred.done(effect))
|
|
2774
|
+
for (let i = 0, len = state.joiners.length; i < len; i++) {
|
|
2913
2775
|
state.joiners[i](effect)
|
|
2914
2776
|
}
|
|
2915
2777
|
return true
|
|
@@ -3005,8 +2867,8 @@ export const deferredSync = dual<
|
|
|
3005
2867
|
export const deferredUnsafeDone = <A, E>(self: Deferred.Deferred<A, E>, effect: Effect.Effect<A, E>): void => {
|
|
3006
2868
|
const state = MutableRef.get(self.state)
|
|
3007
2869
|
if (state._tag === DeferredOpCodes.OP_STATE_PENDING) {
|
|
3008
|
-
|
|
3009
|
-
for (let i = state.joiners.length
|
|
2870
|
+
MutableRef.set(self.state, deferred.done(effect))
|
|
2871
|
+
for (let i = 0, len = state.joiners.length; i < len; i++) {
|
|
3010
2872
|
state.joiners[i](effect)
|
|
3011
2873
|
}
|
|
3012
2874
|
}
|
|
@@ -3019,10 +2881,11 @@ const deferredInterruptJoiner = <A, E>(
|
|
|
3019
2881
|
sync(() => {
|
|
3020
2882
|
const state = MutableRef.get(self.state)
|
|
3021
2883
|
if (state._tag === DeferredOpCodes.OP_STATE_PENDING) {
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
2884
|
+
const index = state.joiners.indexOf(joiner)
|
|
2885
|
+
if (index >= 0) {
|
|
2886
|
+
// we can splice here as the internal state is mutable
|
|
2887
|
+
state.joiners.splice(index, 1)
|
|
2888
|
+
}
|
|
3026
2889
|
}
|
|
3027
2890
|
})
|
|
3028
2891
|
|