@@ -18,6 +18,7 @@ import * as Duration from "./Duration.ts"
1818import type { Effect } from "./Effect.ts"
1919import type { Exit } from "./Exit.ts"
2020import { constUndefined , constVoid , dual , identity } from "./Function.ts"
21+ import { withFiberSucceed } from "./internal/core.ts"
2122import * as InternalEffect from "./internal/effect.ts"
2223import { FiberRuntimeMetricsKey as InternalFiberRuntimeMetricsKey } from "./internal/fiberCachedKeys.ts"
2324import * as InternalRecord from "./internal/record.ts"
@@ -2693,11 +2694,7 @@ export const timer = (name: string, options?: {
26932694 */
26942695export const value = < Input , State > (
26952696 self : Metric < Input , State >
2696- ) : Effect < State > =>
2697- InternalEffect . flatMap (
2698- InternalEffect . context ( ) ,
2699- ( context ) => InternalEffect . sync ( ( ) => self . valueUnsafe ( context ) )
2700- )
2697+ ) : Effect < State > => withFiberSucceed ( ( fiber ) => self . valueUnsafe ( fiber . context ) )
27012698
27022699/**
27032700 * Modifies the metric with the specified input.
@@ -2748,11 +2745,7 @@ export const modify: {
27482745} = dual <
27492746 < Input > ( input : Input ) => < State > ( self : Metric < Input , State > ) => Effect < void > ,
27502747 < Input , State > ( self : Metric < Input , State > , input : Input ) => Effect < void >
2751- > ( 2 , ( self , input ) =>
2752- InternalEffect . flatMap (
2753- InternalEffect . context ( ) ,
2754- ( context ) => InternalEffect . sync ( ( ) => self . modifyUnsafe ( input , context ) )
2755- ) )
2748+ > ( 2 , ( self , input ) => withFiberSucceed ( ( fiber ) => self . modifyUnsafe ( input , fiber . context ) ) )
27562749
27572750/**
27582751 * Updates the metric with the specified input.
@@ -2813,8 +2806,7 @@ export const update: {
28132806 < Input , State > ( self : Metric < Input , State > , input : Input ) => Effect < void >
28142807> (
28152808 2 ,
2816- ( self , input ) =>
2817- InternalEffect . contextWith ( ( services ) => InternalEffect . sync ( ( ) => self . updateUnsafe ( input , services ) ) )
2809+ ( self , input ) => withFiberSucceed ( ( fiber ) => self . updateUnsafe ( input , fiber . context ) )
28182810)
28192811
28202812/**
@@ -2881,7 +2873,7 @@ export interface Registration {
28812873 * @since 4.0.6
28822874 */
28832875export const remove = < Input , State > ( self : Metric < Input , State > ) : Effect < void > =>
2884- InternalEffect . contextWith ( ( context ) => InternalEffect . sync ( ( ) => removeUnsafe ( self , context ) ) )
2876+ withFiberSucceed ( ( fiber ) => removeUnsafe ( self , fiber . context ) )
28852877
28862878/**
28872879 * Removes the series of a metric for the attributes in the provided `Context`
@@ -3176,9 +3168,8 @@ export const withAttributes: {
31763168 * @category snapshotting
31773169 * @since 2.0.0
31783170 */
3179- export const snapshot : Effect < ReadonlyArray < Metric . Snapshot > > = InternalEffect . map (
3180- InternalEffect . context ( ) ,
3181- ( context ) => snapshotUnsafe ( context )
3171+ export const snapshot : Effect < ReadonlyArray < Metric . Snapshot > > = withFiberSucceed ( ( fiber ) =>
3172+ snapshotUnsafe ( fiber . context )
31823173)
31833174
31843175/**
@@ -3236,8 +3227,8 @@ export const snapshot: Effect<ReadonlyArray<Metric.Snapshot>> = InternalEffect.m
32363227 * @category formatting
32373228 * @since 4.0.0
32383229 */
3239- export const dump : Effect < string > = InternalEffect . flatMap ( InternalEffect . context ( ) , ( context ) => {
3240- const metrics = snapshotUnsafe ( context )
3230+ export const dump : Effect < string > = withFiberSucceed ( ( fiber ) => {
3231+ const metrics = snapshotUnsafe ( fiber . context )
32413232 if ( metrics . length > 0 ) {
32423233 const maxNameLength = metrics . reduce ( ( max , metric ) => {
32433234 const length = metric . id . length
@@ -3266,9 +3257,9 @@ export const dump: Effect<string> = InternalEffect.flatMap(InternalEffect.contex
32663257 renderState ( metric )
32673258 ) . join ( "\n" )
32683259 ) . join ( "\n" )
3269- return InternalEffect . succeed ( rendered )
3260+ return rendered
32703261 }
3271- return InternalEffect . succeed ( "" )
3262+ return ""
32723263} )
32733264
32743265/**
0 commit comments