morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::ui::QueueingDispatcher Class Referencefinal

A Dispatcher that holds a queued call the server cannot be reached for, and replays it on reconnect. More...

#include <queueing_dispatcher.hpp>

Inheritance diagram for morph::ui::QueueingDispatcher:
morph::ui::Dispatcher

Public Member Functions

 QueueingDispatcher (Dispatcher &inner, exec::IExecutor *owner)
 Queues around inner, delivering on owner.
std::shared_ptr< ModelChannel > bind (std::string const &typeId, bridge::BindSharing sharing, std::string const &instanceKey) override
 Binds through the wrapped dispatcher.
void replay ()
 Re-sends the held calls, oldest first, one at a time; each caller's completion settles with its replay. A call that still cannot reach the server stops the replay and stays held, with every call after it. Nothing happens while a replay is already running.
std::size_t held () const noexcept
 How many calls are held.
void setOnHeld (std::function< void(std::size_t)> observer)
 Called with the held count whenever it changes, such as for a "waiting to send" indicator.
Public Member Functions inherited from morph::ui::Dispatcher
 Dispatcher (Dispatcher const &)=delete
Dispatcher & operator= (Dispatcher const &)=delete
 Dispatcher (Dispatcher &&)=delete
Dispatcher & operator= (Dispatcher &&)=delete

Detailed Description

A Dispatcher that holds a queued call the server cannot be reached for, and replays it on reconnect.

A call made with CallOptions::queueOffline goes through the wrapped dispatcher. When it fails with backend::DisconnectedError it is held, and the completion the caller has stays pending: the mutation stays pending and its elements stale. Once anything is held, a later queued call joins the back of the queue without being tried, so the server sees the calls in the order they were made. replay re-sends the held calls, oldest first and one at a time, and settles each caller's completion with the replay's reply or failure; a replay that cannot reach the server either stops the replay and stays held for the next one. A call without queueOffline, and an evaluation, are never held: offline, they fail at once.

Single-threaded: every call, and replay, runs on the owner the replies are delivered on. Held calls keep their channel, and with it the model binding, until they settle.

Definition at line 35 of file queueing_dispatcher.hpp.

Constructor & Destructor Documentation

◆ QueueingDispatcher()

morph::ui::QueueingDispatcher::QueueingDispatcher ( Dispatcher & inner,
exec::IExecutor * owner )
inline

Queues around inner, delivering on owner.

Parameters
innerThe dispatcher calls go through. Borrowed: it must outlive this one and every channel it bound.
ownerThe executor replies are delivered on: the runtime's owner. Borrowed.

Definition at line 40 of file queueing_dispatcher.hpp.

Member Function Documentation

◆ bind()

std::shared_ptr< ModelChannel > morph::ui::QueueingDispatcher::bind ( std::string const & typeId,
bridge::BindSharing sharing,
std::string const & instanceKey )
inlinenodiscardoverridevirtual

Binds through the wrapped dispatcher.

Parameters
typeIdThe model's registered type id.
sharingPrivate, or shared.
instanceKeyFor a shared binding, the instance key; empty for the model's shared singleton.
Returns
A channel whose queued calls are held while the server cannot be reached.

Implements morph::ui::Dispatcher.

Definition at line 48 of file queueing_dispatcher.hpp.

◆ replay()

void morph::ui::QueueingDispatcher::replay ( )
inline

Re-sends the held calls, oldest first, one at a time; each caller's completion settles with its replay. A call that still cannot reach the server stops the replay and stays held, with every call after it. Nothing happens while a replay is already running.

Definition at line 56 of file queueing_dispatcher.hpp.

◆ held()

std::size_t morph::ui::QueueingDispatcher::held ( ) const
inlinenodiscardnoexcept

How many calls are held.

Returns
The count.

Definition at line 60 of file queueing_dispatcher.hpp.

◆ setOnHeld()

void morph::ui::QueueingDispatcher::setOnHeld ( std::function< void(std::size_t)> observer)
inline

Called with the held count whenever it changes, such as for a "waiting to send" indicator.

Parameters
observerThe observer; empty for none.

Definition at line 64 of file queueing_dispatcher.hpp.


The documentation for this class was generated from the following file: