Files
endorphin-tessera-gui/examples/gc-lifecycle.endor
T

43 lines
1.4 KiB
Plaintext

// Record ui.stats().objects, call mountCycle(), then inspect phase.value and
// pending.value.status(). Close the tab: the referenced Block still waits.
// releaseCycle() removes both external references; the next objects query
// should return to the same baseline before the five-minute wait finishes.
holder = ui.state(0)
pending = ui.state(0)
phase = ui.state(0)
class CycleRect: RectBlock {
peer: Object
function wait(self: CycleRect): Unit {
gate = ui.sleep(self,"sleep",300000)
phase.set(1)
done = await gate
phase.set(2)
self.peer.title = "等待已结束"
}
function measure(self: CycleRect, mount: Mount, constraints: Constraints): MeasureResult {
observed = self.peer.title
return MeasureResult(180,40)
}
function paint(self: CycleRect, mount: Mount, geometry: Bounds): DisplayList {
observed = self.peer.title
return RectBlock.paint(self,mount,geometry)
}
}
function mountCycle(): Unit {
transient = Page()
transient.title = "临时引用环"
rect = CycleRect(180,40,8,"#3868D9",transient)
transient.render(rect)
holder.set(transient)
phase.set(0)
pending.set(ui.spawn(rect,"workflow",rect.wait))
}
function releaseCycle(): Unit {
holder.value.close()
holder.set(0)
pending.set(0)
}
base = Page()
base.title = "GC 基线"
base.render(TextBlock("关闭临时 Page 后应回收引用环",2))