MCPcopy Index your code
hub / github.com/Effect-TS/effect / getCachedValue

Function getCachedValue

packages/effect/src/internal/effect/circular.ts:277–308  ·  view source on GitHub ↗
(
  self: Effect.Effect<A, E, R>,
  timeToLive: Duration.DurationInput,
  cache: Synchronized.SynchronizedRef<Option.Option<readonly [number, Deferred.Deferred<A, E>]>>
)

Source from the content-addressed store, hash-verified

275
276/** @internal */
277const getCachedValue = <A, E, R>(
278 self: Effect.Effect<A, E, R>,
279 timeToLive: Duration.DurationInput,
280 cache: Synchronized.SynchronizedRef<Option.Option<readonly [number, Deferred.Deferred<A, E>]>>
281): Effect.Effect<A, E, R> =>
282 core.uninterruptibleMask((restore) =>
283 pipe(
284 effect.clockWith((clock) => clock.currentTimeMillis),
285 core.flatMap((time) =>
286 updateSomeAndGetEffectSynchronized(cache, (option) => {
287 switch (option._tag) {
288 case "None": {
289 return Option.some(computeCachedValue(self, timeToLive, time))
290 }
291 case "Some": {
292 const [end] = option.value
293 return end - time <= 0
294 ? Option.some(computeCachedValue(self, timeToLive, time))
295 : Option.none()
296 }
297 }
298 })
299 ),
300 core.flatMap((option) =>
301 Option.isNone(option) ?
302 core.dieMessage(
303 "BUG: Effect.cachedInvalidate - please report an issue at https://github.com/Effect-TS/effect/issues"
304 ) :
305 restore(core.deferredAwait(option.value[1]))
306 )
307 )
308 )
309
310/** @internal */
311const invalidateCache = <A, E>(

Callers 1

circular.tsFile · 0.85

Calls 4

computeCachedValueFunction · 0.85
restoreFunction · 0.85
pipeFunction · 0.70
dieMessageMethod · 0.65

Tested by

no test coverage detected