From af00fc5c4b193ab74a002e5de5a12cf886d810dc Mon Sep 17 00:00:00 2001 From: emilis Date: Wed, 1 Sep 2021 23:06:46 +0200 Subject: [PATCH] Fixed panic for block_on by using smol, this feels wrong --- Cargo.lock | 41 +++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/publish/misskey.rs | 5 +---- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d1dde2..51fbc8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,6 +58,17 @@ dependencies = [ "slab", ] +[[package]] +name = "async-fs" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b3ca4f8ff117c37c278a2f7415ce9be55560b846b5bc4412aaa5d29c1c3dae2" +dependencies = [ + "async-lock", + "blocking", + "futures-lite", +] + [[package]] name = "async-global-executor" version = "2.0.2" @@ -111,6 +122,17 @@ dependencies = [ "event-listener", ] +[[package]] +name = "async-net" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5373304df79b9b4395068fb080369ec7178608827306ce4d081cba51cac551df" +dependencies = [ + "async-io", + "blocking", + "futures-lite", +] + [[package]] name = "async-process" version = "1.1.0" @@ -1206,6 +1228,7 @@ dependencies = [ "rand 0.8.4", "serde", "serde_json", + "smol", "telegram-bot", "thiserror", "tokio 0.2.25", @@ -2457,6 +2480,24 @@ dependencies = [ "maybe-uninit", ] +[[package]] +name = "smol" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cf3b5351f3e783c1d79ab5fc604eeed8b8ae9abd36b166e8b87a089efd85e4" +dependencies = [ + "async-channel", + "async-executor", + "async-fs", + "async-io", + "async-lock", + "async-net", + "async-process", + "blocking", + "futures-lite", + "once_cell", +] + [[package]] name = "socket2" version = "0.3.19" diff --git a/Cargo.toml b/Cargo.toml index 92f10a1..e833586 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,4 @@ mammut = "0.13.0" thiserror = "1.0.26" misskey = "0.2.0" url = "2.2.2" +smol = "1.2.5" diff --git a/src/publish/misskey.rs b/src/publish/misskey.rs index 5e82519..e810f85 100644 --- a/src/publish/misskey.rs +++ b/src/publish/misskey.rs @@ -1,7 +1,6 @@ use futures::Sink; use misskey::{ClientExt, HttpClient}; use std::{error::Error, task::Poll}; -use tokio::runtime::Runtime; use url::Url; pub struct MisskeyPublisher { @@ -27,9 +26,7 @@ impl Sink for MisskeyPublisher { } fn start_send(self: std::pin::Pin<&mut Self>, item: String) -> Result<(), Self::Error> { - let mut runtime = Runtime::new()?; - let fut = self.client.create_note(item); - runtime.block_on(fut)?; + smol::block_on(self.client.create_note(item))?; Ok(()) }