Trait perspective_client::Session
source · pub trait Session<E> {
// Required methods
fn handle_request(
&self,
request: &[u8],
) -> impl Future<Output = Result<(), E>>;
fn poll(&self) -> impl Future<Output = Result<(), E>>;
fn close(self) -> impl Future<Output = ()>;
}Expand description
The server-side representation of a connection to a
[perspective_client::Client]. For each [perspective_client::Client] that
wants to connect to a [Server], a dedicated Session must be created.
The Session handles routing messages emitted by the [Server], as well
as owning any resources the Client may request.
Required Methods§
sourcefn handle_request(&self, request: &[u8]) -> impl Future<Output = Result<(), E>>
fn handle_request(&self, request: &[u8]) -> impl Future<Output = Result<(), E>>
Handle an incoming request from the Client. Calling
Session::handle_request will result in the send_response parameter
which was used to construct this Session to fire one or more times.
:
Client : Session
┏━━━━━━━━━━━━━━━━━━┓ : ┏━━━━━━━━━━━━━━━━━━━━┓
┃ send_request ┃━━━>┃ handle_request (*) ┃
┃ .. ┃ : ┃ .. ┃
┗━━━━━━━━━━━━━━━━━━┛ : ┗━━━━━━━━━━━━━━━━━━━━┛
:
§Arguments
requestAn incoming request message, generated from aClient::new’ssend_requesthandler (which may-or-may-not be local).
sourcefn poll(&self) -> impl Future<Output = Result<(), E>>
fn poll(&self) -> impl Future<Output = Result<(), E>>
Flush any pending messages which may have resulted from previous
Session::handle_request calls. Calling Session::poll may result
in the send_response parameter which was used to construct this (or
other) Session to fire. Whenever a Session::handle_request
method is invoked for a [Server], at least one Session::poll
should be scheduled to clear other clients message queues.
:
Client : Session Server
┏━━━━━━━━━━━━━━━━━━┓ : ┏━━━━━━━━━━━━━━━━━━━┓
┃ send_request ┃━┳━>┃ handle_request ┃ ┏━━━━━━━━━━━━━━━━━━━┓
┃ .. ┃ ┗━>┃ poll (*) ┃━━━>┃ poll (*) ┃
┗━━━━━━━━━━━━━━━━━━┛ : ┃ .. ┃ ┃ .. ┃
: ┗━━━━━━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━┛
sourcefn close(self) -> impl Future<Output = ()>
fn close(self) -> impl Future<Output = ()>
Close this Session, cleaning up any callbacks (e.g. arguments
provided to Session::handle_request or
[perspective_client::View::OnUpdate]) and resources (e.g. views
returned by a call to [perspective_client::Table::view]).
Dropping a Session outside of the context of Session::close
will cause a tracing error-level log to be emitted, but won’t fail.
They will, however, leak.