Send Snapshot on Connected event
This commit is contained in:
parent
cd4b65d9cc
commit
29b7d0ed7a
1 changed files with 12 additions and 6 deletions
|
|
@ -170,6 +170,15 @@ pub struct Snapshot {
|
||||||
pub state: State,
|
pub state: State,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Snapshot {
|
||||||
|
fn from_conn(conn: &Conn) -> Self {
|
||||||
|
Self {
|
||||||
|
conn_tx: conn.tx().clone(),
|
||||||
|
state: conn.state().clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Most of the time, the largest variant (`Packet`) is sent. The size of this
|
// Most of the time, the largest variant (`Packet`) is sent. The size of this
|
||||||
// enum is not critical anyways since it's not constructed that often.
|
// enum is not critical anyways since it's not constructed that often.
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
|
|
@ -187,7 +196,7 @@ pub struct Snapshot {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Connecting(InstanceConfig),
|
Connecting(InstanceConfig),
|
||||||
Connected(InstanceConfig, ConnTx),
|
Connected(InstanceConfig, Snapshot),
|
||||||
Packet(InstanceConfig, ParsedPacket, Snapshot),
|
Packet(InstanceConfig, ParsedPacket, Snapshot),
|
||||||
Disconnected(InstanceConfig),
|
Disconnected(InstanceConfig),
|
||||||
Stopped(InstanceConfig),
|
Stopped(InstanceConfig),
|
||||||
|
|
@ -388,7 +397,7 @@ impl Instance {
|
||||||
.map_err(RunError::CouldNotConnect)?;
|
.map_err(RunError::CouldNotConnect)?;
|
||||||
|
|
||||||
Self::set_cookies(config, cookies);
|
Self::set_cookies(config, cookies);
|
||||||
on_event(Event::Connected(config.clone(), conn.tx().clone()));
|
on_event(Event::Connected(config.clone(), Snapshot::from_conn(&conn)));
|
||||||
|
|
||||||
let conn_tx = conn.tx().clone();
|
let conn_tx = conn.tx().clone();
|
||||||
select! {
|
select! {
|
||||||
|
|
@ -404,10 +413,7 @@ impl Instance {
|
||||||
) -> Result<(), RunError> {
|
) -> Result<(), RunError> {
|
||||||
loop {
|
loop {
|
||||||
let packet = conn.recv().await.map_err(RunError::Conn)?;
|
let packet = conn.recv().await.map_err(RunError::Conn)?;
|
||||||
let snapshot = Snapshot {
|
let snapshot = Snapshot::from_conn(conn);
|
||||||
conn_tx: conn.tx().clone(),
|
|
||||||
state: conn.state().clone(),
|
|
||||||
};
|
|
||||||
|
|
||||||
match &packet.content {
|
match &packet.content {
|
||||||
Ok(Data::SnapshotEvent(snapshot)) => {
|
Ok(Data::SnapshotEvent(snapshot)) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue