fix: gateway simple example
This commit is contained in:
parent
85602de91c
commit
1baa14f857
|
@ -3,6 +3,11 @@ use std::time::Duration;
|
||||||
use chorus::gateway::Gateway;
|
use chorus::gateway::Gateway;
|
||||||
use chorus::{self, types::GatewayIdentifyPayload};
|
use chorus::{self, types::GatewayIdentifyPayload};
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
use safina_timer::sleep_for;
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
use wasmtimer::tokio::sleep_for;
|
||||||
|
|
||||||
/// This example creates a simple gateway connection and a session with an Identify event
|
/// This example creates a simple gateway connection and a session with an Identify event
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
@ -10,7 +15,7 @@ async fn main() {
|
||||||
let websocket_url_spacebar = "wss://gateway.old.server.spacebar.chat/".to_string();
|
let websocket_url_spacebar = "wss://gateway.old.server.spacebar.chat/".to_string();
|
||||||
|
|
||||||
// Initiate the gateway connection, starting a listener in one thread and a heartbeat handler in another
|
// Initiate the gateway connection, starting a listener in one thread and a heartbeat handler in another
|
||||||
let _ = Gateway::spawn(websocket_url_spacebar).await.unwrap();
|
let gateway = Gateway::spawn(websocket_url_spacebar).await.unwrap();
|
||||||
|
|
||||||
// At this point, we are connected to the server and are sending heartbeats, however we still haven't authenticated
|
// At this point, we are connected to the server and are sending heartbeats, however we still haven't authenticated
|
||||||
|
|
||||||
|
@ -26,10 +31,13 @@ async fn main() {
|
||||||
identify.token = token;
|
identify.token = token;
|
||||||
|
|
||||||
// Send off the event
|
// Send off the event
|
||||||
|
gateway.send_identify(identify).await;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
safina_timer::start_timer_thread();
|
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 {
|
||||||
safina_timer::sleep_for(Duration::MAX).await
|
sleep_for(Duration::MAX).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue