feat: switch safina_timer for tokio, fix sleep duration overflow in examples
This commit is contained in:
parent
72936d4f21
commit
34cc344c8d
|
@ -221,7 +221,6 @@ dependencies = [
|
|||
"reqwest",
|
||||
"rustls",
|
||||
"rustls-native-certs",
|
||||
"safina-timer",
|
||||
"serde",
|
||||
"serde-aux",
|
||||
"serde_json",
|
||||
|
@ -1689,15 +1688,6 @@ version = "1.0.16"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
|
||||
|
||||
[[package]]
|
||||
name = "safina-timer"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1081a264d1a3e81b75c4bcd5696094fb6ce470c2ded14cbd47bcb5229079b9df"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schannel"
|
||||
version = "0.1.23"
|
||||
|
|
|
@ -63,7 +63,6 @@ tokio-tungstenite = { version = "0.20.1", features = [
|
|||
] }
|
||||
native-tls = "0.2.11"
|
||||
hostname = "0.3.1"
|
||||
safina-timer = "0.1.11"
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
getrandom = { version = "0.2.12", features = ["js"] }
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::{sync::Arc, time::Duration};
|
|||
use tokio::{self};
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use safina_timer::sleep_for;
|
||||
use tokio::time::sleep;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasmtimer::tokio::sleep;
|
||||
|
||||
|
@ -60,14 +60,8 @@ async fn main() {
|
|||
identify.token = token;
|
||||
gateway.send_identify(identify).await;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
safina_timer::start_timer_thread();
|
||||
|
||||
// Do something on the main thread so we don't quit
|
||||
loop {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
sleep_for(Duration::MAX).await;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
sleep(Duration::MAX).await;
|
||||
sleep(Duration::from_secs(3600)).await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use chorus::gateway::Gateway;
|
|||
use chorus::{self, types::GatewayIdentifyPayload};
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use safina_timer::sleep_for;
|
||||
use tokio::time::sleep;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasmtimer::tokio::sleep;
|
||||
|
||||
|
@ -33,14 +33,8 @@ async fn main() {
|
|||
// Send off the event
|
||||
gateway.send_identify(identify).await;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
safina_timer::start_timer_thread();
|
||||
|
||||
// Do something on the main thread so we don't quit
|
||||
loop {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
sleep_for(Duration::MAX).await;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
sleep(Duration::MAX).await;
|
||||
sleep(Duration::from_secs(3600)).await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@ use futures_util::SinkExt;
|
|||
use log::*;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use std::time::Instant;
|
||||
use tokio::time::Instant;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasmtimer::std::Instant;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use safina_timer::sleep_until;
|
||||
use tokio::time::sleep_until;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasmtimer::tokio::sleep_until;
|
||||
|
||||
|
@ -72,9 +72,6 @@ impl HeartbeatHandler {
|
|||
let mut last_heartbeat_acknowledged = true;
|
||||
let mut last_seq_number: Option<u64> = None;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
safina_timer::start_timer_thread();
|
||||
|
||||
loop {
|
||||
if kill_receive.try_recv().is_ok() {
|
||||
trace!("GW: Closing heartbeat task");
|
||||
|
|
Loading…
Reference in New Issue