effect 2.4.17 → 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/Logger.js +11 -1
- package/dist/cjs/Logger.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 +94 -61
- 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/Logger.d.ts +10 -0
- package/dist/dts/Logger.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/Logger.js +10 -0
- package/dist/esm/Logger.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 +90 -57
- 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/Logger.ts +12 -0
- 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 +136 -111
- 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/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
|
|
|
@@ -15,6 +15,7 @@ import * as MutableHashMap from "../../MutableHashMap.js"
|
|
|
15
15
|
import * as Option from "../../Option.js"
|
|
16
16
|
import { pipeArguments } from "../../Pipeable.js"
|
|
17
17
|
import * as Predicate from "../../Predicate.js"
|
|
18
|
+
import * as Readable from "../../Readable.js"
|
|
18
19
|
import type * as Ref from "../../Ref.js"
|
|
19
20
|
import type * as Schedule from "../../Schedule.js"
|
|
20
21
|
import { currentScheduler } from "../../Scheduler.js"
|
|
@@ -556,10 +557,15 @@ export const synchronizedVariance = {
|
|
|
556
557
|
class SynchronizedImpl<in out A> implements Synchronized.SynchronizedRef<A> {
|
|
557
558
|
readonly [SynchronizedTypeId] = synchronizedVariance
|
|
558
559
|
readonly [internalRef.RefTypeId] = internalRef.refVariance
|
|
560
|
+
readonly [Readable.TypeId]: Readable.TypeId
|
|
559
561
|
constructor(
|
|
560
562
|
readonly ref: Ref.Ref<A>,
|
|
561
563
|
readonly withLock: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
|
|
562
|
-
) {
|
|
564
|
+
) {
|
|
565
|
+
this[Readable.TypeId] = Readable.TypeId
|
|
566
|
+
this.get = internalRef.get(this.ref)
|
|
567
|
+
}
|
|
568
|
+
readonly get: Effect.Effect<A>
|
|
563
569
|
modify<B>(f: (a: A) => readonly [B, A]): Effect.Effect<B> {
|
|
564
570
|
return this.modifyEffect((a) => core.succeed(f(a)))
|
|
565
571
|
}
|
|
@@ -1355,50 +1355,41 @@ export const currentMinimumLogLevel: FiberRef.FiberRef<LogLevel.LogLevel> = glob
|
|
|
1355
1355
|
)
|
|
1356
1356
|
|
|
1357
1357
|
/** @internal */
|
|
1358
|
-
export const
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
}
|
|
1358
|
+
export const loggerWithConsoleLog = <M, O>(self: Logger<M, O>): Logger<M, void> =>
|
|
1359
|
+
internalLogger.makeLogger((opts) => {
|
|
1360
|
+
const services = FiberRefs.getOrDefault(opts.context, defaultServices.currentServices)
|
|
1361
|
+
Context.get(services, consoleTag).unsafe.log(self.log(opts))
|
|
1362
|
+
})
|
|
1363
|
+
|
|
1364
|
+
/** @internal */
|
|
1365
|
+
export const loggerWithConsoleError = <M, O>(self: Logger<M, O>): Logger<M, void> =>
|
|
1366
|
+
internalLogger.makeLogger((opts) => {
|
|
1367
|
+
const services = FiberRefs.getOrDefault(opts.context, defaultServices.currentServices)
|
|
1368
|
+
Context.get(services, consoleTag).unsafe.error(self.log(opts))
|
|
1369
|
+
})
|
|
1363
1370
|
|
|
1364
1371
|
/** @internal */
|
|
1365
1372
|
export const defaultLogger: Logger<unknown, void> = globalValue(
|
|
1366
1373
|
Symbol.for("effect/Logger/defaultLogger"),
|
|
1367
|
-
() =>
|
|
1368
|
-
internalLogger.makeLogger((options) => {
|
|
1369
|
-
const formatted = internalLogger.stringLogger.log(options)
|
|
1370
|
-
getConsole(options.context).log(formatted)
|
|
1371
|
-
})
|
|
1374
|
+
() => loggerWithConsoleLog(internalLogger.stringLogger)
|
|
1372
1375
|
)
|
|
1373
1376
|
|
|
1374
1377
|
/** @internal */
|
|
1375
1378
|
export const jsonLogger: Logger<unknown, void> = globalValue(
|
|
1376
1379
|
Symbol.for("effect/Logger/jsonLogger"),
|
|
1377
|
-
() =>
|
|
1378
|
-
internalLogger.makeLogger((options) => {
|
|
1379
|
-
const formatted = internalLogger.jsonLogger.log(options)
|
|
1380
|
-
getConsole(options.context).log(formatted)
|
|
1381
|
-
})
|
|
1380
|
+
() => loggerWithConsoleLog(internalLogger.jsonLogger)
|
|
1382
1381
|
)
|
|
1383
1382
|
|
|
1384
1383
|
/** @internal */
|
|
1385
1384
|
export const logFmtLogger: Logger<unknown, void> = globalValue(
|
|
1386
1385
|
Symbol.for("effect/Logger/logFmtLogger"),
|
|
1387
|
-
() =>
|
|
1388
|
-
internalLogger.makeLogger((options) => {
|
|
1389
|
-
const formatted = internalLogger.logfmtLogger.log(options)
|
|
1390
|
-
getConsole(options.context).log(formatted)
|
|
1391
|
-
})
|
|
1386
|
+
() => loggerWithConsoleLog(internalLogger.logfmtLogger)
|
|
1392
1387
|
)
|
|
1393
1388
|
|
|
1394
1389
|
/** @internal */
|
|
1395
1390
|
export const structuredLogger: Logger<unknown, void> = globalValue(
|
|
1396
1391
|
Symbol.for("effect/Logger/structuredLogger"),
|
|
1397
|
-
() =>
|
|
1398
|
-
internalLogger.makeLogger((options) => {
|
|
1399
|
-
const formatted = internalLogger.structuredLogger.log(options)
|
|
1400
|
-
getConsole(options.context).log(formatted)
|
|
1401
|
-
})
|
|
1392
|
+
() => loggerWithConsoleLog(internalLogger.structuredLogger)
|
|
1402
1393
|
)
|
|
1403
1394
|
|
|
1404
1395
|
/** @internal */
|
|
@@ -2677,7 +2668,7 @@ export const scopeWith = <A, E, R>(
|
|
|
2677
2668
|
|
|
2678
2669
|
/* @internal */
|
|
2679
2670
|
export const scopedEffect = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, Exclude<R, Scope.Scope>> =>
|
|
2680
|
-
core.flatMap(scopeMake(), (scope) => scopeUse(scope)
|
|
2671
|
+
core.flatMap(scopeMake(), (scope) => scopeUse(effect, scope))
|
|
2681
2672
|
|
|
2682
2673
|
/* @internal */
|
|
2683
2674
|
export const sequentialFinalizers = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
|
@@ -2997,96 +2988,122 @@ export const withRuntimeFlagsScoped = (
|
|
|
2997
2988
|
)
|
|
2998
2989
|
}
|
|
2999
2990
|
|
|
3000
|
-
// circular with
|
|
2991
|
+
// circular with Scope
|
|
2992
|
+
|
|
2993
|
+
/** @internal */
|
|
2994
|
+
export const scopeTag = Context.GenericTag<Scope.Scope>("effect/Scope")
|
|
3001
2995
|
|
|
3002
2996
|
/* @internal */
|
|
3003
|
-
export const
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
2997
|
+
export const scope: Effect.Effect<Scope.Scope, never, Scope.Scope> = scopeTag
|
|
2998
|
+
|
|
2999
|
+
interface ScopeImpl extends Scope.CloseableScope {
|
|
3000
|
+
state: {
|
|
3001
|
+
readonly _tag: "Open"
|
|
3002
|
+
readonly finalizers: Set<Scope.Scope.Finalizer>
|
|
3003
|
+
} | {
|
|
3004
|
+
readonly _tag: "Closed"
|
|
3005
|
+
readonly exit: Exit.Exit<unknown, unknown>
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
|
|
3009
|
+
const scopeUnsafeAddFinalizer = (scope: ScopeImpl, fin: Scope.Scope.Finalizer): void => {
|
|
3010
|
+
if (scope.state._tag === "Open") {
|
|
3011
|
+
scope.state.finalizers.add(fin)
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
const ScopeImplProto: Omit<ScopeImpl, "strategy" | "state"> = {
|
|
3016
|
+
[core.ScopeTypeId]: core.ScopeTypeId,
|
|
3017
|
+
[core.CloseableScopeTypeId]: core.CloseableScopeTypeId,
|
|
3018
|
+
pipe() {
|
|
3019
|
+
return pipeArguments(this, arguments)
|
|
3020
|
+
},
|
|
3021
|
+
fork(this: ScopeImpl, strategy) {
|
|
3022
|
+
return core.sync(() => {
|
|
3023
|
+
const newScope = scopeUnsafeMake(strategy)
|
|
3024
|
+
if (this.state._tag === "Closed") {
|
|
3025
|
+
newScope.state = this.state
|
|
3026
|
+
return newScope
|
|
3027
|
+
}
|
|
3028
|
+
const fin = (exit: Exit.Exit<unknown, unknown>) => newScope.close(exit)
|
|
3029
|
+
this.state.finalizers.add(fin)
|
|
3030
|
+
scopeUnsafeAddFinalizer(newScope, (_) =>
|
|
3031
|
+
core.sync(() => {
|
|
3032
|
+
if (this.state._tag === "Open") {
|
|
3033
|
+
this.state.finalizers.delete(fin)
|
|
3034
|
+
}
|
|
3035
|
+
}))
|
|
3036
|
+
return newScope
|
|
3037
|
+
})
|
|
3038
|
+
},
|
|
3039
|
+
close(this: ScopeImpl, exit) {
|
|
3040
|
+
return core.suspend(() => {
|
|
3041
|
+
if (this.state._tag === "Closed") {
|
|
3011
3042
|
return core.unit
|
|
3012
3043
|
}
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
Option.getOrElse(() => core.exitUnit)
|
|
3027
|
-
)
|
|
3044
|
+
const finalizers = Array.from(this.state.finalizers.values()).reverse()
|
|
3045
|
+
this.state = { _tag: "Closed", exit }
|
|
3046
|
+
if (finalizers.length === 0) {
|
|
3047
|
+
return core.unit
|
|
3048
|
+
}
|
|
3049
|
+
return executionStrategy.isSequential(this.strategy) ?
|
|
3050
|
+
pipe(
|
|
3051
|
+
core.forEachSequential(finalizers, (fin) => core.exit(fin(exit))),
|
|
3052
|
+
core.flatMap((results) =>
|
|
3053
|
+
pipe(
|
|
3054
|
+
core.exitCollectAll(results),
|
|
3055
|
+
Option.map(core.exitAsUnit),
|
|
3056
|
+
Option.getOrElse(() => core.exitUnit)
|
|
3028
3057
|
)
|
|
3029
|
-
)
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
)
|
|
3058
|
+
)
|
|
3059
|
+
) :
|
|
3060
|
+
executionStrategy.isParallel(this.strategy) ?
|
|
3061
|
+
pipe(
|
|
3062
|
+
forEachParUnbounded(finalizers, (fin) => core.exit(fin(exit)), false),
|
|
3063
|
+
core.flatMap((results) =>
|
|
3064
|
+
pipe(
|
|
3065
|
+
core.exitCollectAll(results, { parallel: true }),
|
|
3066
|
+
Option.map(core.exitAsUnit),
|
|
3067
|
+
Option.getOrElse(() => core.exitUnit)
|
|
3039
3068
|
)
|
|
3040
|
-
)
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
)
|
|
3069
|
+
)
|
|
3070
|
+
) :
|
|
3071
|
+
pipe(
|
|
3072
|
+
forEachParN(finalizers, this.strategy.parallelism, (fin) => core.exit(fin(exit)), false),
|
|
3073
|
+
core.flatMap((results) =>
|
|
3074
|
+
pipe(
|
|
3075
|
+
core.exitCollectAll(results, { parallel: true }),
|
|
3076
|
+
Option.map(core.exitAsUnit),
|
|
3077
|
+
Option.getOrElse(() => core.exitUnit)
|
|
3049
3078
|
)
|
|
3050
3079
|
)
|
|
3080
|
+
)
|
|
3081
|
+
})
|
|
3082
|
+
},
|
|
3083
|
+
addFinalizer(this: ScopeImpl, fin) {
|
|
3084
|
+
return core.suspend(() => {
|
|
3085
|
+
if (this.state._tag === "Closed") {
|
|
3086
|
+
return fin(this.state.exit)
|
|
3051
3087
|
}
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
/** @internal */
|
|
3058
|
-
export const scopeTag = Context.GenericTag<Scope.Scope>("effect/Scope")
|
|
3088
|
+
this.state.finalizers.add(fin)
|
|
3089
|
+
return core.unit
|
|
3090
|
+
})
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3059
3093
|
|
|
3060
|
-
|
|
3061
|
-
|
|
3094
|
+
const scopeUnsafeMake = (
|
|
3095
|
+
strategy: ExecutionStrategy.ExecutionStrategy = executionStrategy.sequential
|
|
3096
|
+
): ScopeImpl => {
|
|
3097
|
+
const scope = Object.create(ScopeImplProto)
|
|
3098
|
+
scope.strategy = strategy
|
|
3099
|
+
scope.state = { _tag: "Open", finalizers: new Set() }
|
|
3100
|
+
return scope
|
|
3101
|
+
}
|
|
3062
3102
|
|
|
3063
3103
|
/* @internal */
|
|
3064
3104
|
export const scopeMake = (
|
|
3065
3105
|
strategy: ExecutionStrategy.ExecutionStrategy = executionStrategy.sequential
|
|
3066
|
-
): Effect.Effect<Scope.Scope.Closeable> =>
|
|
3067
|
-
core.map(core.releaseMapMake, (rm): Scope.Scope.Closeable => ({
|
|
3068
|
-
[core.ScopeTypeId]: core.ScopeTypeId,
|
|
3069
|
-
[core.CloseableScopeTypeId]: core.CloseableScopeTypeId,
|
|
3070
|
-
strategy,
|
|
3071
|
-
pipe() {
|
|
3072
|
-
return pipeArguments(this, arguments)
|
|
3073
|
-
},
|
|
3074
|
-
fork: (strategy) =>
|
|
3075
|
-
core.uninterruptible(
|
|
3076
|
-
pipe(
|
|
3077
|
-
scopeMake(strategy),
|
|
3078
|
-
core.flatMap((scope) =>
|
|
3079
|
-
pipe(
|
|
3080
|
-
core.releaseMapAdd(rm, (exit) => core.scopeClose(scope, exit)),
|
|
3081
|
-
core.tap((fin) => core.scopeAddFinalizerExit(scope, fin)),
|
|
3082
|
-
core.as(scope)
|
|
3083
|
-
)
|
|
3084
|
-
)
|
|
3085
|
-
)
|
|
3086
|
-
),
|
|
3087
|
-
close: (exit) => core.asUnit(releaseMapReleaseAll(strategy, exit)(rm)),
|
|
3088
|
-
addFinalizer: (fin) => core.asUnit(core.releaseMapAdd(fin)(rm))
|
|
3089
|
-
}))
|
|
3106
|
+
): Effect.Effect<Scope.Scope.Closeable> => core.sync(() => scopeUnsafeMake(strategy))
|
|
3090
3107
|
|
|
3091
3108
|
/* @internal */
|
|
3092
3109
|
export const scopeExtend = dual<
|
|
@@ -3561,15 +3578,23 @@ export const makeSpanScoped = (
|
|
|
3561
3578
|
readonly context?: Context.Context<never> | undefined
|
|
3562
3579
|
}
|
|
3563
3580
|
): Effect.Effect<Tracer.Span, never, Scope.Scope> =>
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
span.
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3581
|
+
core.uninterruptible(
|
|
3582
|
+
core.withFiberRuntime((fiber) => {
|
|
3583
|
+
const scope = Context.unsafeGet(fiber.getFiberRef(core.currentContext), scopeTag)
|
|
3584
|
+
const span = internalEffect.unsafeMakeSpan(fiber, name, options)
|
|
3585
|
+
const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
|
|
3586
|
+
const clock_ = Context.get(fiber.getFiberRef(defaultServices.currentServices), clock.clockTag)
|
|
3587
|
+
return core.as(
|
|
3588
|
+
core.scopeAddFinalizerExit(scope, (exit) =>
|
|
3589
|
+
core.sync(() => {
|
|
3590
|
+
if (span.status._tag === "Ended") {
|
|
3591
|
+
return
|
|
3592
|
+
}
|
|
3593
|
+
span.end(timingEnabled ? clock_.unsafeCurrentTimeNanos() : BigInt(0), exit)
|
|
3594
|
+
})),
|
|
3595
|
+
span
|
|
3596
|
+
)
|
|
3597
|
+
})
|
|
3573
3598
|
)
|
|
3574
3599
|
|
|
3575
3600
|
/* @internal */
|
package/src/internal/hashMap.ts
CHANGED
|
@@ -270,7 +270,7 @@ export const unsafeGet = Dual.dual<
|
|
|
270
270
|
>(2, (self, key) => {
|
|
271
271
|
const element = getHash(self, key, Hash.hash(key))
|
|
272
272
|
if (Option.isNone(element)) {
|
|
273
|
-
throw new Error("
|
|
273
|
+
throw new Error("Expected map to contain key")
|
|
274
274
|
}
|
|
275
275
|
return element.value
|
|
276
276
|
})
|
package/src/internal/matcher.ts
CHANGED
|
@@ -508,7 +508,7 @@ export const orElseAbsurd = <I, R, RA, A, Pr>(
|
|
|
508
508
|
self: Matcher<I, R, RA, A, Pr>
|
|
509
509
|
): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A> =>
|
|
510
510
|
orElse(() => {
|
|
511
|
-
throw new Error("absurd")
|
|
511
|
+
throw new Error("effect/Match/orElseAbsurd: absurd")
|
|
512
512
|
})(self)
|
|
513
513
|
|
|
514
514
|
/** @internal */
|
|
@@ -565,6 +565,8 @@ export const option: <I, F, R, A, Pr>(
|
|
|
565
565
|
})
|
|
566
566
|
}) as any
|
|
567
567
|
|
|
568
|
+
const getExhaustiveAbsurdErrorMessage = "effect/Match/exhaustive: absurd"
|
|
569
|
+
|
|
568
570
|
/** @internal */
|
|
569
571
|
export const exhaustive: <I, F, A, Pr>(
|
|
570
572
|
self: Matcher<I, F, never, A, Pr>
|
|
@@ -578,7 +580,7 @@ export const exhaustive: <I, F, A, Pr>(
|
|
|
578
580
|
return toEither.right
|
|
579
581
|
}
|
|
580
582
|
|
|
581
|
-
throw new Error(
|
|
583
|
+
throw new Error(getExhaustiveAbsurdErrorMessage)
|
|
582
584
|
}
|
|
583
585
|
|
|
584
586
|
return (u: I): A => {
|
|
@@ -589,6 +591,6 @@ export const exhaustive: <I, F, A, Pr>(
|
|
|
589
591
|
return result.right as any
|
|
590
592
|
}
|
|
591
593
|
|
|
592
|
-
throw new Error(
|
|
594
|
+
throw new Error(getExhaustiveAbsurdErrorMessage)
|
|
593
595
|
}
|
|
594
596
|
}) as any
|
package/src/internal/ref.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { dual } from "../Function.js"
|
|
|
3
3
|
import * as MutableRef from "../MutableRef.js"
|
|
4
4
|
import * as Option from "../Option.js"
|
|
5
5
|
import { pipeArguments } from "../Pipeable.js"
|
|
6
|
+
import * as Readable from "../Readable.js"
|
|
6
7
|
import type * as Ref from "../Ref.js"
|
|
7
8
|
import * as core from "./core.js"
|
|
8
9
|
|
|
@@ -17,7 +18,12 @@ export const refVariance = {
|
|
|
17
18
|
|
|
18
19
|
class RefImpl<in out A> implements Ref.Ref<A> {
|
|
19
20
|
readonly [RefTypeId] = refVariance
|
|
20
|
-
|
|
21
|
+
readonly [Readable.TypeId]: Readable.TypeId
|
|
22
|
+
constructor(readonly ref: MutableRef.MutableRef<A>) {
|
|
23
|
+
this[Readable.TypeId] = Readable.TypeId
|
|
24
|
+
this.get = core.sync(() => MutableRef.get(this.ref))
|
|
25
|
+
}
|
|
26
|
+
readonly get: Effect.Effect<A>
|
|
21
27
|
modify<B>(f: (a: A) => readonly [B, A]): Effect.Effect<B> {
|
|
22
28
|
return core.sync(() => {
|
|
23
29
|
const current = MutableRef.get(this.ref)
|
|
@@ -40,7 +46,7 @@ export const unsafeMake = <A>(value: A): Ref.Ref<A> => new RefImpl(MutableRef.ma
|
|
|
40
46
|
export const make = <A>(value: A): Effect.Effect<Ref.Ref<A>> => core.sync(() => unsafeMake(value))
|
|
41
47
|
|
|
42
48
|
/** @internal */
|
|
43
|
-
export const get = <A>(self: Ref.Ref<A>) => self.
|
|
49
|
+
export const get = <A>(self: Ref.Ref<A>) => self.get
|
|
44
50
|
|
|
45
51
|
/** @internal */
|
|
46
52
|
export const set = dual<
|
|
@@ -3,6 +3,7 @@ import { dual, pipe } from "../../Function.js"
|
|
|
3
3
|
import * as Option from "../../Option.js"
|
|
4
4
|
import * as Interval from "../../ScheduleInterval.js"
|
|
5
5
|
import type * as Intervals from "../../ScheduleIntervals.js"
|
|
6
|
+
import { getBugErrorMessage } from "../errors.js"
|
|
6
7
|
|
|
7
8
|
/** @internal */
|
|
8
9
|
const IntervalsSymbolKey = "effect/ScheduleIntervals"
|
|
@@ -109,7 +110,7 @@ const unionLoop = (
|
|
|
109
110
|
that = Chunk.tailNonEmpty(that)
|
|
110
111
|
}
|
|
111
112
|
} else {
|
|
112
|
-
throw new Error("
|
|
113
|
+
throw new Error(getBugErrorMessage("Intervals.unionLoop"))
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
return make(pipe(acc, Chunk.prepend(interval), Chunk.reverse))
|