runtime_activity.go RawHistoryFolder
1package port
2
3import "context"
4
5// RuntimeActivitySnapshot is an engine-neutral view of outstanding native
6// runtime work that must settle before the process may idle out. Counts only:
7// generations and acknowledgement correlation live with the implementation.
8type RuntimeActivitySnapshot struct {
9 // PendingCreations counts accepted browser creations not yet resolved
10 // through OnAfterCreated or a definitive failure.
11 PendingCreations int
12 // ActiveViews counts registered live views, including views whose
13 // native close has started but whose GTK teardown is outstanding.
14 ActiveViews int
15 // PendingCleanup counts native-closed views whose queued GTK
16 // bridge/popup cleanup has not completed.
17 PendingCleanup int
18 // ActiveDownloads counts downloads with a terminal event outstanding.
19 ActiveDownloads int
20}
21
22// Quiescent reports whether no native work is outstanding.
23func (s RuntimeActivitySnapshot) Quiescent() bool {
24 return s.PendingCreations == 0 && s.ActiveViews == 0 && s.PendingCleanup == 0 && s.ActiveDownloads == 0
25}
26
27// RuntimeActivity is the application-port boundary for native runtime
28// quiescence. The initial snapshot and subscription are race-safe and
29// sequenced: Subscribe delivers the current snapshot synchronously, then all
30// later transitions in order. Unsubscribe at shutdown.
31type RuntimeActivity interface {
32 Snapshot() RuntimeActivitySnapshot
33 Subscribe(func(RuntimeActivitySnapshot)) (unsubscribe func())
34}
35
36// PersistenceDrain is the narrow activity/drain boundary for persistence
37// owners whose saves cross the GTK/database boundary. Active covers pending
38// debounce, in-flight capture/execution, and unsettled terminal failure.
39// WaitSettled blocks until settled or ctx ends; it must never be called on
40// the GTK thread when capture dispatches there.
41type PersistenceDrain interface {
42 Active() bool
43 WaitSettled(ctx context.Context) error
44}
45
46// AdmissionBoundary is the admission/work-lease contract shared by the relay
47// listener and the shutdown/residency policy. Infrastructure provides the
48// implementation; application code depends only on this boundary.
49type AdmissionBoundary interface {
50 // Acquire takes one work lease, reporting false when admission is
51 // closed. Callers send the existing error response instead of
52 // acknowledging.
53 Acquire() bool
54 // Release returns one work lease on dispatch settlement.
55 Release()
56 // Close atomically stops admission; in-flight leases drain.
57 Close()
58 // Reopen resumes admission after an invalidated seal.
59 Reopen()
60 // Closed reports whether admission is stopped.
61 Closed() bool
62 // Active reports the number of held leases.
63 Active() int
64 // OnDrained registers a callback for every transition to zero leases.
65 // Callbacks run without the gate lock and must not reenter it.
66 OnDrained(func())
67 // WaitDrained blocks until no leases are held or ctx ends, reporting
68 // false on expiry so shutdown never waits forever.
69 WaitDrained(ctx context.Context) bool
70}