MCPcopy Create free account
hub / github.com/Effect-TS/effect / updateServiceScoped

Function updateServiceScoped

packages/effect/src/internal/effect.ts:2125–2148  ·  view source on GitHub ↗
(
  service: Context.Key<I, A>,
  update: (value: A) => A,
  options?: {
    readonly reset?: ((original: A, updated: A, current: A) => A) | undefined
  } | undefined
)

Source from the content-addressed store, hash-verified

2123
2124/** @internal */
2125export const updateServiceScoped = <I, A>(
2126 service: Context.Key<I, A>,
2127 update: (value: A) => A,
2128 options?: {
2129 readonly reset?: ((original: A, updated: A, current: A) => A) | undefined
2130 } | undefined
2131): Effect.Effect<void, never, I | Scope.Scope> =>
2132 uninterruptible(withFiber((fiber) => {
2133 const original = Context.getUnsafe(fiber.context, service)
2134 const updated = update(original)
2135 fiber.setContext(Context.add(fiber.context, service, updated))
2136 return scopeAddFinalizerExit(Context.getUnsafe(fiber.context, scopeTag), (_) => {
2137 const current = Context.getUnsafe(fiber.context, service)
2138 let next: A
2139 if (options?.reset === undefined) {
2140 if (current !== updated) return void_
2141 next = original
2142 } else {
2143 next = options.reset(original, updated, current)
2144 }
2145 fiber.setContext(Context.add(fiber.context, service, next))
2146 return void_
2147 })
2148 }))
2149
2150/** @internal */
2151export const context = <R = never>(): Effect.Effect<Context.Context<R>> => getContext as any

Callers

nothing calls this directly

Calls 5

getUnsafeMethod · 0.80
setContextMethod · 0.65
addMethod · 0.65
resetMethod · 0.65
updateFunction · 0.50

Tested by

no test coverage detected