pub struct Connection(/* private fields */);Expand description
The connection to zero-cache (Connection in
packages/zero-client/src/client/connection.ts).
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn state(&self) -> ConnectionState
pub fn state(&self) -> ConnectionState
The state now.
Sourcepub fn update_needed(&self) -> Option<UpdateNeededReason>
pub fn update_needed(&self) -> Option<UpdateNeededReason>
Why the app must be updated to sync, once the server said so
(onUpdateNeeded). Reconnecting doesn’t help.
Sourcepub fn subscribe(
&self,
listener: impl Fn(&ConnectionState) + 'static,
) -> Box<dyn Fn()>
pub fn subscribe( &self, listener: impl Fn(&ConnectionState) + 'static, ) -> Box<dyn Fn()>
Calls listener on every change of state. Returns the function
that removes it.
Sourcepub fn connect(&self, auth: ConnectAuth) -> Result<(), Error>
pub fn connect(&self, auth: ConnectAuth) -> Result<(), Error>
Resumes connecting from needs-auth or error (connect in
connection.ts). From any other state it only applies auth, and
after a disconnect for a missing cache_url it never reconnects.
auth first sets or clears the token, as connect({auth}) does;
when already connected, the server gets a new non-empty token in
updateAuth. A token on a client without a user_id is an
Error::Connection of kind Internal (JS’s rejection), and
nothing changes.
It returns once the connection is asked to resume, not once it
has: JS’s promise waits for the next state, which
subscribe follows here.