One UI executor; call dispatch only between frames, never during layout/paint. create captures its calling thread. Callbacks run there without the queue lock. No method mutates a widget or requests a frame: downstream callbacks own invalidation. Destruction must occur on UI, outside dispatch, after UI tokens; publishers may survive it. Callbacks must terminate promptly: budgets bound counts, not application callback wall time.
More...
#include <scheduler.hpp>
|
|
using | ErrorSink = void (*)(void *, SchedulerError) noexcept |
| | UI error sink; borrowed context must outlive Scheduler, sink must not throw.
|
|
|
| ~Scheduler () |
| | Stop/reclaim on owner; no joins; destroying from a callback is prohibited.
|
|
| Scheduler (const Scheduler &)=delete |
|
Scheduler & | operator= (const Scheduler &)=delete |
| std::expected< UiScope, SchedulerError > | makeScope () |
| | UI-only; closed/identity exhaustion are explicit.
|
| template<class T, class Callback> |
| std::expected< SchedulerConnection< T >, SchedulerError > | connect (const UiScope &scope, Callback &&callback, SchedulerLane lane=SchedulerLane::DATA, SchedulerOverflow overflow=SchedulerOverflow::REJECT) |
| | UI-only typed registration; copies/moves and owns callback, translating bad_alloc. Callback receives an independent snapshot owner. Foreign/closed scope, invalid enum, registration capacity or allocation failure rejects the operation without registration. REPLACE_LATEST is data-only and keeps at most one pending value per sender.
|
| template<class Callback> |
| std::expected< Subscription, SchedulerError > | at (const UiScope &scope, SchedulerTime deadline, Callback &&callback) |
| | Register a cancellable one-shot timer at an absolute clock millisecond. Due timers run in deadline/registration order, within timer_budget; no catch-up loss.
|
| std::expected< SchedulerDispatch, SchedulerError > | dispatch () |
| | UI-only; nested dispatch rejected, callback exceptions contained.
|
| std::expected< SchedulerWake, SchedulerError > | waitFor (std::chrono::milliseconds timeout) |
| | UI-only bounded blocking wait; negative timeout invalid, dispatch reentry rejected. Real timeout is independent of injected time. Advance fake time then wake explicitly.
|
|
void | requestStop () noexcept |
| | Worker-safe while this object lives; sender variant can outlive it.
|
| std::expected< void, SchedulerError > | stop () |
| | UI-only close and reclamation, including self-stop.
|
| SchedulerMetrics | metrics () const |
| | Thread-safe copy, usable after stop.
|
| Diagnostics * | diagnostics () const noexcept |
| | Borrow the configured recorder; its lifetime is retained by this scheduler.
|
|
| static std::expected< std::unique_ptr< Scheduler >, SchedulerError > | create (SchedulerOptions options={}, SchedulerClock clock={}, ErrorSink sink=nullptr, void *sink_context=nullptr) |
| | Allocate bounded storage; invalid limits/no memory return errors without partial state. Allocation in caller expressions is outside this factory's boundary.
|
One UI executor; call dispatch only between frames, never during layout/paint. create captures its calling thread. Callbacks run there without the queue lock. No method mutates a widget or requests a frame: downstream callbacks own invalidation. Destruction must occur on UI, outside dispatch, after UI tokens; publishers may survive it. Callbacks must terminate promptly: budgets bound counts, not application callback wall time.
◆ at()
Register a cancellable one-shot timer at an absolute clock millisecond. Due timers run in deadline/registration order, within timer_budget; no catch-up loss.
- Template Parameters
-
| Callback | Copy-constructible callable storable in std::function and invocable as an lvalue without arguments; its return value is ignored. |
- Parameters
-
| scope | Live scope belonging to this scheduler; closing it cancels the timer. |
| deadline | Absolute millisecond deadline in the configured monotonic clock. |
| callback | Callable copied/moved into UI-owned registration storage. |
- Returns
- Cancellation token, or WRONG_THREAD, WRONG_SCHEDULER, closed, WOULD_BLOCK, IDENTITY_EXHAUSTED, or NO_MEMORY.
- Note
- Exceptions other than std::bad_alloc propagate when materializing the callback.
◆ connect()
template<class T, class Callback>
UI-only typed registration; copies/moves and owns callback, translating bad_alloc. Callback receives an independent snapshot owner. Foreign/closed scope, invalid enum, registration capacity or allocation failure rejects the operation without registration. REPLACE_LATEST is data-only and keeps at most one pending value per sender.
- Template Parameters
-
| T | Transitively immutable payload type; final ownership may be released on UI or a producer. |
| Callback | Copy-constructible callable storable in std::function and invocable as an lvalue with std::shared_ptr<const T>; its return value is ignored. |
- Parameters
-
| scope | Live scope belonging to this scheduler; it controls callback lifetime. |
| callback | Callable copied/moved into UI-owned registration storage. |
| lane | Queue whose capacity and dispatch budget apply. |
| overflow | Reject on capacity or replace this sender's pending data snapshot. |
- Returns
- Subscription and publisher, or WRONG_THREAD, WRONG_SCHEDULER, closed, INVALID_ARGUMENT, WOULD_BLOCK, IDENTITY_EXHAUSTED, or NO_MEMORY.
- Note
- Exceptions other than std::bad_alloc propagate when materializing the callback.
◆ create()
Allocate bounded storage; invalid limits/no memory return errors without partial state. Allocation in caller expressions is outside this factory's boundary.
- Parameters
-
| options | Positive queue, registration and dispatch limits; storage is reserved up front. |
| clock | Borrowed monotonic clock; a null reader selects steady_clock. |
| sink | Optional nonthrowing callback-failure sink, invoked on the creating UI thread. |
| sink_context | Borrowed sink state that must outlive this scheduler. |
- Returns
- New UI-owned scheduler, INVALID_ARGUMENT for invalid/unrepresentable limits, or NO_MEMORY.
◆ diagnostics()
| Diagnostics * portals::Scheduler::diagnostics |
( |
| ) |
const |
|
noexcept |
Borrow the configured recorder; its lifetime is retained by this scheduler.
- Returns
- Recorder pointer, or null when diagnostics were not configured.
◆ dispatch()
UI-only; nested dispatch rejected, callback exceptions contained.
- Returns
- Counts for this control/timer/data cycle, including caught callback failures and stop; WRONG_THREAD or REENTRANT_DISPATCH rejects before any callback starts.
◆ makeScope()
UI-only; closed/identity exhaustion are explicit.
- Returns
- New UI-owned scope, or WRONG_THREAD, closed, or IDENTITY_EXHAUSTED.
◆ metrics()
Thread-safe copy, usable after stop.
- Returns
- Owning snapshot of both queue counters and aggregate dispatch counters.
◆ stop()
UI-only close and reclamation, including self-stop.
- Returns
- Success after closure and UI reclamation, including repeated stop; WRONG_THREAD otherwise.
◆ waitFor()
UI-only bounded blocking wait; negative timeout invalid, dispatch reentry rejected. Real timeout is independent of injected time. Advance fake time then wake explicitly.
- Parameters
-
| timeout | Nonnegative maximum real elapsed wait; zero only checks readiness. |
- Returns
- ready for queued/due work or explicit wake, stopped after stop, timeout after the wait, or WRONG_THREAD, REENTRANT_DISPATCH, or INVALID_ARGUMENT on rejection.
The documentation for this class was generated from the following file: