mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 18:31:52 +00:00
* addHealthCheck on Daemons * fix bug that prevents domains without protocols from being deleted * fixes from testing * version bump * add sdk version to UI * fix useEntrypoint * fix dependency health check error display * minor fixes * beta.29 * fixes from testing * beta.30 * set /etc/os-release (#2918) * remove check-monitor from kiosk (#2059) * add units for progress (#2693) * use new progress type * alpha.7 * fix up pwa stuff * fix wormhole-squashfs and prune boot (#2964) * don't exit on expected errors * use bash --------- Co-authored-by: Matt Hill <mattnine@protonmail.com>
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
export abstract class Drop {
|
|
private static weak: { [id: number]: Drop } = {}
|
|
private static registry = new FinalizationRegistry((id: number) => {
|
|
const weak = Drop.weak[id]
|
|
if (weak) weak.drop()
|
|
})
|
|
private static idCtr: number = 0
|
|
private dropId?: number
|
|
private dropRef?: { id: number } | WeakRef<{ id: number }>
|
|
protected constructor() {
|
|
this.dropId = Drop.idCtr++
|
|
this.dropRef = { id: this.dropId }
|
|
const weak = this.weak()
|
|
Drop.weak[this.dropId] = weak
|
|
Drop.registry.register(this.dropRef, this.dropId, this.dropRef)
|
|
|
|
return new Proxy(this, {
|
|
set(target: any, prop, value) {
|
|
if (prop === "dropRef" || prop == "dropId") return false
|
|
target[prop] = value
|
|
;(weak as any)[prop] = value
|
|
return true
|
|
},
|
|
})
|
|
}
|
|
protected register() {}
|
|
protected weak(): this {
|
|
const weak = Object.assign(Object.create(Object.getPrototypeOf(this)), this)
|
|
if (this.dropRef) weak.ref = new WeakRef(this.dropRef)
|
|
return weak
|
|
}
|
|
abstract onDrop(): void
|
|
drop(): void {
|
|
if (!this.dropRef || !this.dropId) return
|
|
this.onDrop()
|
|
this.leak()
|
|
}
|
|
leak(): this {
|
|
if (!this.dropRef || !this.dropId) return this
|
|
Drop.registry.unregister(this.dropRef)
|
|
delete Drop.weak[this.dropId]
|
|
delete this.dropRef
|
|
delete this.dropId
|
|
return this
|
|
}
|
|
}
|