Add Effect v4 support, Fast Refresh tooling, and revamped docs #56
@@ -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<void> {
|
||||
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<ScopeRegistryService.Entry>(),
|
||||
HashMap.empty<ScopeRegistryService.Key, ScopeRegistryService.Entry>(),
|
||||
] 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,
|
||||
|
||||
Reference in New Issue
Block a user