Skip to main content

Module stream

Module stream 

Source
Expand description

Keeping the data stream open.

A blocking connection on its own thread rather than an asynchronous one. The clients this feeds are user interfaces with main loops of their own, and asking each of them to host an async runtime for one socket is a poor trade. What comes out is a plain channel of events, which any main loop can drain.

The reconnection is the point of the whole file. A wireless link on a boat drops; a client that needed restarting afterwards would be useless. Nothing here reports failure upwards as fatal – it reports that the link is down, keeps trying, and lets the consumer decide what to show meanwhile. That decision has already been made elsewhere: the fix goes stale and says so.

§Being told when to look, without being told how

wake, passed to Connection::open, is called from this thread the moment Connection::drain has something worth calling for. It is deliberately the only thing this crate knows about whichever main loop is on the other end – a plain Fn() + Send, not a toolkit-specific idle source or anything else naming a toolkit, so that a client on any platform, and sk-probe on a bare terminal, all satisfy it the same way each already satisfies its own main loop.

It is told, not handed the data: Events still only ever leave through Connection::drain, on the consumer’s own timing. A callback invoked once per message would turn a burst of deltas after a reconnect into a burst of redraws, which is the one thing polling a receiver on a loop protected against by accident; wake protects against it on purpose, firing once for a burst and staying quiet until the consumer has drained and something new arrives after that.

Structs§

Connection
A running connection.

Enums§

Event
What the connection reports.