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, HashMap, Layer, Option, Scope, Semaphore, Stream, SubscriptionRef } from "effect"
|
||||
import { type Cause, Context, DateTime, type Duration, Effect, Equal, Exit, HashMap, Layer, Option, Order, Scope, Semaphore, Stream, SubscriptionRef } from "effect"
|
||||
|
||||
|
||||
export interface ScopeRegistryService {
|
||||
@@ -159,18 +159,20 @@ export class ScopeRegistryServiceImpl implements ScopeRegistryService {
|
||||
getNextExpiration(
|
||||
entries: HashMap.HashMap<ScopeRegistryService.Key, ScopeRegistryService.Entry>,
|
||||
): Option.Option<DateTime.Utc> {
|
||||
let earliest: DateTime.Utc | undefined
|
||||
|
||||
for (const entry of HashMap.values(entries)) {
|
||||
if (
|
||||
entry.leases === 0 &&
|
||||
entry.expiresAt._tag === "Some" &&
|
||||
(!earliest || DateTime.isLessThan(entry.expiresAt.value, earliest))
|
||||
)
|
||||
earliest = entry.expiresAt.value
|
||||
}
|
||||
|
||||
return Option.fromNullishOr(earliest)
|
||||
return HashMap.reduce(
|
||||
entries,
|
||||
Option.none<DateTime.Utc>(),
|
||||
(earliest, entry) => Option.match(
|
||||
Option.filter(entry.expiresAt, () => entry.leases === 0),
|
||||
{
|
||||
onNone: () => earliest,
|
||||
onSome: expiresAt => Option.some(Option.match(earliest, {
|
||||
onNone: () => expiresAt,
|
||||
onSome: Order.min<DateTime.Utc>(DateTime.Order)(expiresAt),
|
||||
})),
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user