bad idea
This commit is contained in:
parent
5dc87f6095
commit
f86d23bac0
|
@ -29,6 +29,7 @@ impl HeartbeatHandler {
|
||||||
websocket_tx: Arc<Mutex<Sink>>,
|
websocket_tx: Arc<Mutex<Sink>>,
|
||||||
kill_rc: tokio::sync::broadcast::Receiver<()>,
|
kill_rc: tokio::sync::broadcast::Receiver<()>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
println!("HBH: Creating new self");
|
||||||
let (send, receive) = tokio::sync::mpsc::channel(32);
|
let (send, receive) = tokio::sync::mpsc::channel(32);
|
||||||
let kill_receive = kill_rc.resubscribe();
|
let kill_receive = kill_rc.resubscribe();
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ impl HeartbeatHandler {
|
||||||
wasm_bindgen_futures::spawn_local(async move {
|
wasm_bindgen_futures::spawn_local(async move {
|
||||||
Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive).await;
|
Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive).await;
|
||||||
});
|
});
|
||||||
|
println!("HBH: Spawned task");
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
heartbeat_interval,
|
heartbeat_interval,
|
||||||
|
@ -57,14 +59,18 @@ impl HeartbeatHandler {
|
||||||
mut receive: Receiver<HeartbeatThreadCommunication>,
|
mut receive: Receiver<HeartbeatThreadCommunication>,
|
||||||
mut kill_receive: tokio::sync::broadcast::Receiver<()>,
|
mut kill_receive: tokio::sync::broadcast::Receiver<()>,
|
||||||
) {
|
) {
|
||||||
|
println!("HBH: Running task");
|
||||||
let mut last_heartbeat_timestamp: Instant = time::Instant::now();
|
let mut last_heartbeat_timestamp: Instant = time::Instant::now();
|
||||||
let mut last_heartbeat_acknowledged = true;
|
let mut last_heartbeat_acknowledged = true;
|
||||||
let mut last_seq_number: Option<u64> = None;
|
let mut last_seq_number: Option<u64> = None;
|
||||||
|
println!("HBH: Initialized variables");
|
||||||
|
|
||||||
safina_timer::start_timer_thread();
|
safina_timer::start_timer_thread();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
println!("HBH: L0");
|
||||||
if kill_receive.try_recv().is_ok() {
|
if kill_receive.try_recv().is_ok() {
|
||||||
|
println!("HBH: dying");
|
||||||
trace!("GW: Closing heartbeat task");
|
trace!("GW: Closing heartbeat task");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -78,6 +84,8 @@ impl HeartbeatHandler {
|
||||||
|
|
||||||
let mut should_send = false;
|
let mut should_send = false;
|
||||||
|
|
||||||
|
println!("HBH: L1");
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
() = sleep_until(last_heartbeat_timestamp + timeout) => {
|
() = sleep_until(last_heartbeat_timestamp + timeout) => {
|
||||||
should_send = true;
|
should_send = true;
|
||||||
|
@ -104,9 +112,13 @@ impl HeartbeatHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("HBH: L2");
|
||||||
|
|
||||||
if should_send {
|
if should_send {
|
||||||
trace!("GW: Sending Heartbeat..");
|
trace!("GW: Sending Heartbeat..");
|
||||||
|
|
||||||
|
println!("HBH: L3, sending");
|
||||||
|
|
||||||
let heartbeat = types::GatewayHeartbeat {
|
let heartbeat = types::GatewayHeartbeat {
|
||||||
op: GATEWAY_HEARTBEAT,
|
op: GATEWAY_HEARTBEAT,
|
||||||
d: last_seq_number,
|
d: last_seq_number,
|
||||||
|
@ -125,6 +137,8 @@ impl HeartbeatHandler {
|
||||||
|
|
||||||
last_heartbeat_timestamp = time::Instant::now();
|
last_heartbeat_timestamp = time::Instant::now();
|
||||||
last_heartbeat_acknowledged = false;
|
last_heartbeat_acknowledged = false;
|
||||||
|
|
||||||
|
println!("HBH: L4, sending done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,10 @@ async fn test_gateway_authenticate() {
|
||||||
identify.token = bundle.user.token.clone();
|
identify.token = bundle.user.token.clone();
|
||||||
|
|
||||||
gateway.send_identify(identify).await;
|
gateway.send_identify(identify).await;
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await;
|
||||||
|
|
||||||
|
// deliberately fail the test so we get the output
|
||||||
|
assert!(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||||
|
|
Loading…
Reference in New Issue