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