Add Effect v4 support, Fast Refresh tooling, and revamped docs #56
@@ -25,7 +25,6 @@ export declare namespace ScopeRegistryService {
|
||||
|
||||
export interface Entry {
|
||||
readonly scope: Scope.Closeable
|
||||
readonly leases: number
|
||||
readonly expiresAt: Option.Option<DateTime.Utc>
|
||||
readonly finalizerExecutionDebounce: Duration.Input
|
||||
}
|
||||
@@ -49,13 +48,11 @@ export class ScopeRegistryServiceImpl implements ScopeRegistryService {
|
||||
const now = yield* DateTime.now
|
||||
const entry = Equal.byReference<ScopeRegistryService.Entry>({
|
||||
scope: yield* Scope.make(options.finalizerExecutionStrategy),
|
||||
leases: 0,
|
||||
expiresAt: Option.some(DateTime.addDuration(now, options.finalizerExecutionDebounce)),
|
||||
finalizerExecutionDebounce: options.finalizerExecutionDebounce,
|
||||
})
|
||||
|
||||
yield* SubscriptionRef.update(this.ref, HashMap.set(key, entry))
|
||||
|
||||
return entry
|
||||
})
|
||||
}
|
||||
@@ -63,25 +60,15 @@ export class ScopeRegistryServiceImpl implements ScopeRegistryService {
|
||||
commit(key: ScopeRegistryService.Key): Effect.Effect<ScopeRegistryService.Entry, Cause.NoSuchElementError> {
|
||||
return this.updateEntry(key, entry => Equal.byReference({
|
||||
...entry,
|
||||
leases: entry.leases + 1,
|
||||
expiresAt: Option.none(),
|
||||
}))
|
||||
}
|
||||
|
||||
release(key: ScopeRegistryService.Key): Effect.Effect<ScopeRegistryService.Entry, Cause.NoSuchElementError> {
|
||||
return Effect.flatMap(DateTime.now, now => this.updateEntry(key, entry => {
|
||||
if (entry.leases === 0)
|
||||
return entry
|
||||
|
||||
const leases = entry.leases - 1
|
||||
return Equal.byReference({
|
||||
...entry,
|
||||
leases,
|
||||
expiresAt: leases === 0
|
||||
? Option.some(DateTime.addDuration(now, entry.finalizerExecutionDebounce))
|
||||
: Option.none(),
|
||||
})
|
||||
}))
|
||||
return Effect.flatMap(DateTime.now, now => this.updateEntry(key, entry => Equal.byReference({
|
||||
...entry,
|
||||
expiresAt: Option.some(DateTime.addDuration(now, entry.finalizerExecutionDebounce)),
|
||||
})))
|
||||
}
|
||||
|
||||
get run(): Effect.Effect<void> {
|
||||
@@ -134,7 +121,7 @@ export class ScopeRegistryServiceImpl implements ScopeRegistryService {
|
||||
entries => {
|
||||
const expired: ScopeRegistryService.Entry[] = []
|
||||
const remaining = HashMap.filter(entries, entry => {
|
||||
const shouldClose = entry.leases === 0 && Option.exists(
|
||||
const shouldClose = Option.exists(
|
||||
entry.expiresAt,
|
||||
expiresAt => DateTime.isLessThanOrEqualTo(expiresAt, now),
|
||||
)
|
||||
@@ -162,16 +149,13 @@ export class ScopeRegistryServiceImpl implements ScopeRegistryService {
|
||||
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),
|
||||
})),
|
||||
},
|
||||
),
|
||||
(earliest, entry) => Option.match(entry.expiresAt, {
|
||||
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