Remove 'handle', add wasm friendly task spawning
This commit is contained in:
parent
93c12fff63
commit
f8979b7feb
|
@ -4,7 +4,8 @@ use std::time::{self, Duration, Instant};
|
||||||
use tokio::sync::mpsc::{Receiver, Sender};
|
use tokio::sync::mpsc::{Receiver, Sender};
|
||||||
|
|
||||||
use safina_timer::sleep_until;
|
use safina_timer::sleep_until;
|
||||||
use tokio::task::{self, JoinHandle};
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
use tokio::task;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::types;
|
use crate::types;
|
||||||
|
@ -20,8 +21,6 @@ pub(super) struct HeartbeatHandler {
|
||||||
pub heartbeat_interval: Duration,
|
pub heartbeat_interval: Duration,
|
||||||
/// The send channel for the heartbeat thread
|
/// The send channel for the heartbeat thread
|
||||||
pub send: Sender<HeartbeatThreadCommunication>,
|
pub send: Sender<HeartbeatThreadCommunication>,
|
||||||
/// The handle of the thread
|
|
||||||
handle: JoinHandle<()>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HeartbeatHandler {
|
impl HeartbeatHandler {
|
||||||
|
@ -33,15 +32,18 @@ impl HeartbeatHandler {
|
||||||
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();
|
||||||
|
|
||||||
// FIXME: Doesn't work in WASM
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
let handle: JoinHandle<()> = task::spawn(async move {
|
task::spawn(async move {
|
||||||
|
Self::heartbeat_task(websocket_tx, heartbeat_interval, receive, kill_receive).await;
|
||||||
|
});
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
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;
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
heartbeat_interval,
|
heartbeat_interval,
|
||||||
send,
|
send,
|
||||||
handle,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue