From 7e816d041e1900756faa855b974869d592f6586d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Thu, 23 Jul 2026 03:13:17 +0200 Subject: [PATCH] Fix --- packages/effect-fc-next/src/ScopeRegistry.ts | 31 +++++++++----------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/effect-fc-next/src/ScopeRegistry.ts b/packages/effect-fc-next/src/ScopeRegistry.ts index 643f1d8..7720aaf 100644 --- a/packages/effect-fc-next/src/ScopeRegistry.ts +++ b/packages/effect-fc-next/src/ScopeRegistry.ts @@ -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 { @@ -115,22 +115,19 @@ export class ScopeRegistryServiceImpl implements ScopeRegistryService { get closeExpired(): Effect.Effect { return Effect.flatMap(DateTime.now, now => SubscriptionRef.modify( this.ref, - entries => { - const expired: ScopeRegistryService.Entry[] = [] - const remaining = HashMap.filter(entries, entry => { - const shouldClose = Option.exists( - entry.expiresAt, - expiresAt => DateTime.isLessThanOrEqualTo(expiresAt, now), - ) - - if (shouldClose) - expired.push(entry) - - return !shouldClose - }) - - return [expired, remaining] - }, + entries => HashMap.reduce( + entries, + [ + Chunk.empty(), + HashMap.empty(), + ] as const, + ([expired, remaining], entry, key) => Option.exists( + entry.expiresAt, + expiresAt => DateTime.isLessThanOrEqualTo(expiresAt, now), + ) + ? [Chunk.append(expired, entry), remaining] as const + : [expired, HashMap.set(remaining, key, entry)] as const, + ), )).pipe( Effect.flatMap(entries => Effect.forEach( entries,