<K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<void>
<K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<void>Extends the idle time for a resource in the RcMap. If the RcMap has an
idleTimeToLive configured, calling touch will reset the expiration
timer for the specified key.
When to use
Use to keep an idle resource alive longer without acquiring a new reference.
Example (Extending resource idle time)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
const map = yield* RcMap.make({
lookup: (key: string) =>
Effect.acquireRelease(
Effect.succeed(`Resource: ${key}`),
() => Effect.log(`Released ${key}`)
),
idleTimeToLive: "10 seconds"
})
// Get a resource
yield* RcMap.get(map, "session")
// Touch the resource to extend its idle time
// This resets the 10-second expiration timer
yield* RcMap.touch(map, "session")
// The resource will now live for another 10 seconds
// from the time it was touched
}).pipe(Effect.scoped)export const const touch: {
<K>(key: K): <A, E>(
self: RcMap<K, A, E>
) => Effect.Effect<void>
<K, A, E>(
self: RcMap<K, A, E>,
key: K
): Effect.Effect<void>
}
Extends the idle time for a resource in the RcMap. If the RcMap has an
idleTimeToLive configured, calling touch will reset the expiration
timer for the specified key.
When to use
Use to keep an idle resource alive longer without acquiring a new reference.
Example (Extending resource idle time)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
const map = yield* RcMap.make({
lookup: (key: string) =>
Effect.acquireRelease(
Effect.succeed(`Resource: ${key}`),
() => Effect.log(`Released ${key}`)
),
idleTimeToLive: "10 seconds"
})
// Get a resource
yield* RcMap.get(map, "session")
// Touch the resource to extend its idle time
// This resets the 10-second expiration timer
yield* RcMap.touch(map, "session")
// The resource will now live for another 10 seconds
// from the time it was touched
}).pipe(Effect.scoped)
touch: {
<function (type parameter) K in <K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<void>K>(key: Kkey: function (type parameter) K in <K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<void>K): <function (type parameter) A in <A, E>(self: RcMap<K, A, E>): Effect.Effect<void>A, function (type parameter) E in <A, E>(self: RcMap<K, A, E>): Effect.Effect<void>E>(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, A, E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface RcMap<in out K, in out A, in out E = never>An RcMap is a reference-counted map data structure that manages the lifecycle
of resources indexed by keys. Resources are lazily acquired and automatically
released when no longer in use.
When to use
Use to share scoped resources by key while automatically releasing them after
their last active reference is gone.
Example (Inspecting a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
// Create an RcMap that manages database connections
const dbConnectionMap = yield* RcMap.make({
lookup: (dbName: string) =>
Effect.acquireRelease(
Effect.succeed(`Connection to ${dbName}`),
(conn) => Effect.log(`Closing ${conn}`)
),
capacity: 10,
idleTimeToLive: "5 minutes"
})
// The RcMap interface provides access to:
// - lookup: Function to acquire resources
// - capacity: Maximum number of resources
// - idleTimeToLive: Time before idle resources are released
// - state: Current state of the map
console.log(`Capacity: ${dbConnectionMap.capacity}`)
}).pipe(Effect.scoped)
RcMap<function (type parameter) K in <K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<void>K, function (type parameter) A in <A, E>(self: RcMap<K, A, E>): Effect.Effect<void>A, function (type parameter) E in <A, E>(self: RcMap<K, A, E>): Effect.Effect<void>E>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<void>K, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<void>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<void>E>(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, A, E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface RcMap<in out K, in out A, in out E = never>An RcMap is a reference-counted map data structure that manages the lifecycle
of resources indexed by keys. Resources are lazily acquired and automatically
released when no longer in use.
When to use
Use to share scoped resources by key while automatically releasing them after
their last active reference is gone.
Example (Inspecting a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
// Create an RcMap that manages database connections
const dbConnectionMap = yield* RcMap.make({
lookup: (dbName: string) =>
Effect.acquireRelease(
Effect.succeed(`Connection to ${dbName}`),
(conn) => Effect.log(`Closing ${conn}`)
),
capacity: 10,
idleTimeToLive: "5 minutes"
})
// The RcMap interface provides access to:
// - lookup: Function to acquire resources
// - capacity: Maximum number of resources
// - idleTimeToLive: Time before idle resources are released
// - state: Current state of the map
console.log(`Capacity: ${dbConnectionMap.capacity}`)
}).pipe(Effect.scoped)
RcMap<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<void>K, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<void>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<void>E>, key: Kkey: function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<void>K): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
} = import dualdual(
2,
<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): anyK, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): anyA, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): anyE>(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, A, E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface RcMap<in out K, in out A, in out E = never>An RcMap is a reference-counted map data structure that manages the lifecycle
of resources indexed by keys. Resources are lazily acquired and automatically
released when no longer in use.
When to use
Use to share scoped resources by key while automatically releasing them after
their last active reference is gone.
Example (Inspecting a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
// Create an RcMap that manages database connections
const dbConnectionMap = yield* RcMap.make({
lookup: (dbName: string) =>
Effect.acquireRelease(
Effect.succeed(`Connection to ${dbName}`),
(conn) => Effect.log(`Closing ${conn}`)
),
capacity: 10,
idleTimeToLive: "5 minutes"
})
// The RcMap interface provides access to:
// - lookup: Function to acquire resources
// - capacity: Maximum number of resources
// - idleTimeToLive: Time before idle resources are released
// - state: Current state of the map
console.log(`Capacity: ${dbConnectionMap.capacity}`)
}).pipe(Effect.scoped)
RcMap<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): anyK, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): anyA, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): anyE>, key: Kkey: function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): anyK) =>
import EffectEffect.clockWith((clock: Clock(parameter) clock: {
currentTimeMillisUnsafe: () => number;
currentTimeMillis: Effect<number>;
currentTimeNanosUnsafe: () => bigint;
currentTimeNanos: Effect<bigint>;
sleep: (duration: Duration.Duration) => Effect<void>;
}
clock) => {
if (self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, A, E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.RcMap<K, A, E>.state: State<K, A, E>state._tag: "Open" | "Closed"_tag === "Closed") {
return import EffectEffect.void
}
const const o: Option<State.Entry<A, E>>o = import MutableHashMapMutableHashMap.get(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, A, E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.RcMap<K, A, E>.state: State<K, A, E>(property) RcMap<K, A, E>.state: {
_tag: "Open";
map: MutableHashMap.MutableHashMap<K, Entry<A, E>>;
}
state.State<K, A, E>.Open<K, A, E>.map: MutableHashMap.MutableHashMap<K, Entry<A, E>>(property) State<K, A, E>.Open<K, A, E>.map: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
map, key: Kkey)
if (const o: Option<State.Entry<A, E>>o._tag === "None" || import DurationDuration.isZero(const o: Some<State.Entry<A, E>>const o: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
o.value.idleTimeToLive)) {
return import EffectEffect.void
}
const const entry: anyconst entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry = const o: Some<State.Entry<A, E>>const o: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
o.value
const entry: anyconst entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry.expiresAt = clock: Clock(parameter) clock: {
currentTimeMillisUnsafe: () => number;
currentTimeMillis: Effect<number>;
currentTimeNanosUnsafe: () => bigint;
currentTimeNanos: Effect<bigint>;
sleep: (duration: Duration.Duration) => Effect<void>;
}
clock.currentTimeMillisUnsafe() + import DurationDuration.toMillis(const entry: anyconst entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry.idleTimeToLive)
return import EffectEffect.void
})
)