@@ -1,4 +1,4 @@
|
|||||||
import { type Cause, Context, DateTime, type Duration, Effect, Equal, Exit, flow, HashMap, Layer, Option, Order, Scope, Semaphore, Stream, SubscriptionRef } from "effect"
|
import { type Cause, Chunk, Context, DateTime, type Duration, Effect, Equal, Exit, HashMap, Layer, Option, Order, Scope, Semaphore, Stream, SubscriptionRef } from "effect"
|
||||||
|
|
||||||
|
|
||||||
export interface ScopeRegistryService {
|
export interface ScopeRegistryService {
|
||||||
@@ -115,22 +115,19 @@ export class ScopeRegistryServiceImpl implements ScopeRegistryService {
|
|||||||
get closeExpired(): Effect.Effect<void> {
|
get closeExpired(): Effect.Effect<void> {
|
||||||
return Effect.flatMap(DateTime.now, now => SubscriptionRef.modify(
|
return Effect.flatMap(DateTime.now, now => SubscriptionRef.modify(
|
||||||
this.ref,
|
this.ref,
|
||||||
entries => {
|
entries => HashMap.reduce(
|
||||||
const expired: ScopeRegistryService.Entry[] = []
|
entries,
|
||||||
const remaining = HashMap.filter(entries, entry => {
|
[
|
||||||
const shouldClose = Option.exists(
|
Chunk.empty<ScopeRegistryService.Entry>(),
|
||||||
entry.expiresAt,
|
HashMap.empty<ScopeRegistryService.Key, ScopeRegistryService.Entry>(),
|
||||||
expiresAt => DateTime.isLessThanOrEqualTo(expiresAt, now),
|
] as const,
|
||||||
)
|
([expired, remaining], entry, key) => Option.exists(
|
||||||
|
entry.expiresAt,
|
||||||
if (shouldClose)
|
expiresAt => DateTime.isLessThanOrEqualTo(expiresAt, now),
|
||||||
expired.push(entry)
|
)
|
||||||
|
? [Chunk.append(expired, entry), remaining] as const
|
||||||
return !shouldClose
|
: [expired, HashMap.set(remaining, key, entry)] as const,
|
||||||
})
|
),
|
||||||
|
|
||||||
return [expired, remaining]
|
|
||||||
},
|
|
||||||
)).pipe(
|
)).pipe(
|
||||||
Effect.flatMap(entries => Effect.forEach(
|
Effect.flatMap(entries => Effect.forEach(
|
||||||
entries,
|
entries,
|
||||||
|
|||||||
Reference in New Issue
Block a user