feat: switch safina_timer for tokio, fix sleep duration overflow in examples

This commit is contained in:
kozabrada123 2024-01-19 15:48:59 +01:00
parent 72936d4f21
commit 34cc344c8d
5 changed files with 6 additions and 32 deletions

10
Cargo.lock generated
View File

@ -221,7 +221,6 @@ dependencies = [
"reqwest", "reqwest",
"rustls", "rustls",
"rustls-native-certs", "rustls-native-certs",
"safina-timer",
"serde", "serde",
"serde-aux", "serde-aux",
"serde_json", "serde_json",
@ -1689,15 +1688,6 @@ version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" 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]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.23" version = "0.1.23"

View File

@ -63,7 +63,6 @@ tokio-tungstenite = { version = "0.20.1", features = [
] } ] }
native-tls = "0.2.11" native-tls = "0.2.11"
hostname = "0.3.1" hostname = "0.3.1"
safina-timer = "0.1.11"
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2.12", features = ["js"] } getrandom = { version = "0.2.12", features = ["js"] }

View File

@ -9,7 +9,7 @@ use std::{sync::Arc, time::Duration};
use tokio::{self}; use tokio::{self};
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use safina_timer::sleep_for; use tokio::time::sleep;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasmtimer::tokio::sleep; use wasmtimer::tokio::sleep;
@ -60,14 +60,8 @@ async fn main() {
identify.token = token; identify.token = token;
gateway.send_identify(identify).await; 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 // Do something on the main thread so we don't quit
loop { loop {
#[cfg(not(target_arch = "wasm32"))] sleep(Duration::from_secs(3600)).await;
sleep_for(Duration::MAX).await;
#[cfg(target_arch = "wasm32")]
sleep(Duration::MAX).await;
} }
} }

View File

@ -4,7 +4,7 @@ use chorus::gateway::Gateway;
use chorus::{self, types::GatewayIdentifyPayload}; use chorus::{self, types::GatewayIdentifyPayload};
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use safina_timer::sleep_for; use tokio::time::sleep;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasmtimer::tokio::sleep; use wasmtimer::tokio::sleep;
@ -33,14 +33,8 @@ async fn main() {
// Send off the event // Send off the event
gateway.send_identify(identify).await; 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 // Do something on the main thread so we don't quit
loop { loop {
#[cfg(not(target_arch = "wasm32"))] sleep(Duration::from_secs(3600)).await;
sleep_for(Duration::MAX).await;
#[cfg(target_arch = "wasm32")]
sleep(Duration::MAX).await;
} }
} }

View File

@ -2,12 +2,12 @@ use futures_util::SinkExt;
use log::*; use log::*;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use std::time::Instant; use tokio::time::Instant;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasmtimer::std::Instant; use wasmtimer::std::Instant;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use safina_timer::sleep_until; use tokio::time::sleep_until;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasmtimer::tokio::sleep_until; use wasmtimer::tokio::sleep_until;
@ -72,9 +72,6 @@ impl HeartbeatHandler {
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;
#[cfg(not(target_arch = "wasm32"))]
safina_timer::start_timer_thread();
loop { loop {
if kill_receive.try_recv().is_ok() { if kill_receive.try_recv().is_ok() {
trace!("GW: Closing heartbeat task"); trace!("GW: Closing heartbeat task");