remove runtime and clean up example

master
Devin R 2020-04-14 18:14:14 -04:00
parent cf029b2e4f
commit 6d1cbcd9ca
1 changed files with 4 additions and 22 deletions

View File

@ -1,5 +1,3 @@
use std::ops::Deref;
use std::sync::Arc;
use std::{env, process::exit}; use std::{env, process::exit};
use url::Url; use url::Url;
@ -8,13 +6,10 @@ use matrix_sdk::{
events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent}, events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent},
AsyncClient, AsyncClientConfig, EventEmitter, Room, SyncSettings, AsyncClient, AsyncClientConfig, EventEmitter, Room, SyncSettings,
}; };
use tokio::runtime::{Handle, Runtime};
use tokio::sync::mpsc::{channel, Sender};
use tokio::sync::Mutex; use tokio::sync::Mutex;
struct CommandBot { struct CommandBot {
client: Mutex<AsyncClient>, client: Mutex<AsyncClient>,
// sender: Sender<(RoomId, MessageEventContent)>
} }
impl CommandBot { impl CommandBot {
@ -66,7 +61,6 @@ async fn login_and_sync(
homeserver_url: String, homeserver_url: String,
username: String, username: String,
password: String, password: String,
exec: Handle,
) -> Result<(), matrix_sdk::Error> { ) -> Result<(), matrix_sdk::Error> {
let client_config = AsyncClientConfig::new(); let client_config = AsyncClientConfig::new();
// .proxy("http://localhost:8080")? // .proxy("http://localhost:8080")?
@ -89,16 +83,13 @@ async fn login_and_sync(
println!("logged in as {}", username); println!("logged in as {}", username);
exec.spawn(async move {
client.sync_forever(SyncSettings::new(), |_| async {}).await; client.sync_forever(SyncSettings::new(), |_| async {}).await;
})
.await
.unwrap();
Ok(()) Ok(())
} }
fn main() -> Result<(), matrix_sdk::Error> { #[tokio::main]
async fn main() -> Result<(), matrix_sdk::Error> {
let (homeserver_url, username, password) = let (homeserver_url, username, password) =
match (env::args().nth(1), env::args().nth(2), env::args().nth(3)) { match (env::args().nth(1), env::args().nth(2), env::args().nth(3)) {
(Some(a), Some(b), Some(c)) => (a, b, c), (Some(a), Some(b), Some(c)) => (a, b, c),
@ -111,15 +102,6 @@ fn main() -> Result<(), matrix_sdk::Error> {
} }
}; };
let mut runtime = tokio::runtime::Builder::new() login_and_sync(homeserver_url, username, password).await?;
.basic_scheduler()
.threaded_scheduler()
.enable_all()
.build()
.unwrap();
let exec = runtime.handle().clone();
runtime.block_on(async { login_and_sync(homeserver_url, username, password, exec).await })?;
Ok(()) Ok(())
} }