Merge 13ef3e40a8
into 82a3f98db7
This commit is contained in:
commit
dca9b07e6f
|
@ -69,6 +69,7 @@ hostname = "0.3.1"
|
|||
getrandom = { version = "0.2.12", features = ["js"] }
|
||||
ws_stream_wasm = "0.7.4"
|
||||
wasm-bindgen-futures = "0.4.39"
|
||||
web-sys = "0.3.67"
|
||||
|
||||
[dev-dependencies]
|
||||
lazy_static = "1.4.0"
|
||||
|
|
|
@ -29,6 +29,9 @@ impl HeartbeatHandler {
|
|||
websocket_tx: Arc<Mutex<Sink>>,
|
||||
kill_rc: tokio::sync::broadcast::Receiver<()>,
|
||||
) -> Self {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1("HBH: Creating new self");
|
||||
|
||||
let (send, receive) = tokio::sync::mpsc::channel(32);
|
||||
let kill_receive = kill_rc.resubscribe();
|
||||
|
||||
|
@ -40,6 +43,8 @@ impl HeartbeatHandler {
|
|||
wasm_bindgen_futures::spawn_local(async move {
|
||||
Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive).await;
|
||||
});
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1("HBH: Spawned task");
|
||||
|
||||
Self {
|
||||
heartbeat_interval,
|
||||
|
@ -57,14 +62,26 @@ impl HeartbeatHandler {
|
|||
mut receive: Receiver<HeartbeatThreadCommunication>,
|
||||
mut kill_receive: tokio::sync::broadcast::Receiver<()>,
|
||||
) {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1("HBH: Running task");
|
||||
let mut last_heartbeat_timestamp: Instant = time::Instant::now();
|
||||
let mut last_heartbeat_acknowledged = true;
|
||||
let mut last_seq_number: Option<u64> = None;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1("HBH: Initialized variables");
|
||||
|
||||
safina_timer::start_timer_thread();
|
||||
|
||||
loop {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1("HBH: L0");
|
||||
|
||||
println!("HBH: L0");
|
||||
if kill_receive.try_recv().is_ok() {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1("HBH: dying");
|
||||
|
||||
println!("HBH: dying");
|
||||
trace!("GW: Closing heartbeat task");
|
||||
break;
|
||||
}
|
||||
|
@ -78,6 +95,11 @@ impl HeartbeatHandler {
|
|||
|
||||
let mut should_send = false;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1("HBH: L1");
|
||||
|
||||
println!("HBH: L1");
|
||||
|
||||
tokio::select! {
|
||||
() = sleep_until(last_heartbeat_timestamp + timeout) => {
|
||||
should_send = true;
|
||||
|
@ -104,9 +126,19 @@ impl HeartbeatHandler {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1("HBH: L2");
|
||||
|
||||
println!("HBH: L2");
|
||||
|
||||
if should_send {
|
||||
trace!("GW: Sending Heartbeat..");
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1("HBH: L3, sending");
|
||||
|
||||
println!("HBH: L3, sending");
|
||||
|
||||
let heartbeat = types::GatewayHeartbeat {
|
||||
op: GATEWAY_HEARTBEAT,
|
||||
d: last_seq_number,
|
||||
|
@ -125,6 +157,9 @@ impl HeartbeatHandler {
|
|||
|
||||
last_heartbeat_timestamp = time::Instant::now();
|
||||
last_heartbeat_acknowledged = false;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1("HBH: L4, sending done");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,10 @@ async fn test_gateway_authenticate() {
|
|||
identify.token = bundle.user.token.clone();
|
||||
|
||||
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)]
|
||||
|
|
Loading…
Reference in New Issue