Skip to content

Commit

Permalink
Make tokio's rt-multi-thread enabled again in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dscottboggs committed Jan 1, 2023
1 parent 6ba0cd0 commit f830671
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ optional = true

[dependencies.tokio]
version = "1.22.0"
features = ["macros"]
features = ["macros", "io-util", "time"]

[dependencies.tokio-util]
version = "0.7.4"
Expand All @@ -91,5 +91,6 @@ all = ["toml", "json", "env"]
# default = ["reqwest/default-tls"]
default = ["reqwest/default-tls"]
env = ["envy"]
mt = ["tokio/rt-multi-thread"]
json = []
rustls-tls = ["reqwest/rustls-tls"]
17 changes: 14 additions & 3 deletions examples/follow_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ mod register;
use mastodon_async::Result;

#[cfg(feature = "toml")]
#[tokio::main]
async fn main() -> Result<()> {
async fn run() -> Result<()> {
let mastodon = register::get_mastodon_data().await?;
let input = register::read_line("Enter the account id you'd like to follow: ")?;
let new_follow = mastodon.follow(input.trim()).await?;
Expand All @@ -14,10 +13,22 @@ async fn main() -> Result<()> {
Ok(())
}

#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
run().await
}

#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
run().await
}

#[cfg(not(feature = "toml"))]
fn main() {
println!(
"examples require the `toml` feature, run this command for this example:\n\ncargo run \
--example follow_profile --features toml\n"
--example follow_profile --features toml,mt\n"
);
}
15 changes: 13 additions & 2 deletions examples/follows_me.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ mod register;
use mastodon_async::Result;

#[cfg(feature = "toml")]
#[tokio::main]
async fn main() -> Result<()> {
async fn run() -> Result<()> {
use futures::StreamExt;

let mastodon = register::get_mastodon_data().await?;
Expand All @@ -21,6 +20,18 @@ async fn main() -> Result<()> {
Ok(())
}

#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
run().await
}

#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
run().await
}

#[cfg(not(feature = "toml"))]
fn main() {
println!(
Expand Down
15 changes: 13 additions & 2 deletions examples/get_statuses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ mod register;
use mastodon_async::Result;

#[cfg(feature = "toml")]
#[tokio::main]
async fn main() -> Result<()> {
async fn run() -> Result<()> {
use futures_util::StreamExt;
use mastodon_async::StatusesRequest;

Expand All @@ -23,6 +22,18 @@ async fn main() -> Result<()> {
Ok(())
}

#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
run().await
}

#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
run().await
}

#[cfg(not(feature = "toml"))]
fn main() {
println!(
Expand Down
15 changes: 13 additions & 2 deletions examples/home_timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use futures_util::StreamExt;
use mastodon_async::Result;

#[cfg(feature = "toml")]
#[tokio::main]
async fn main() -> Result<()> {
async fn run() -> Result<()> {
register::get_mastodon_data()
.await?
.get_home_timeline()
Expand All @@ -25,6 +24,18 @@ async fn main() -> Result<()> {
Ok(())
}

#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
run().await
}

#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
run().await
}

#[cfg(not(feature = "toml"))]
fn main() {
println!(
Expand Down
15 changes: 13 additions & 2 deletions examples/log_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use log::{as_serde, info};
use mastodon_async::Result;

#[cfg(feature = "toml")]
#[tokio::main]
async fn main() -> Result<()> {
async fn run() -> Result<()> {
use log::warn;

femme::with_level(log::LevelFilter::Info);
Expand All @@ -27,6 +26,18 @@ async fn main() -> Result<()> {
Ok(())
}

#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
run().await
}

#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
run().await
}

#[cfg(not(feature = "toml"))]
fn main() {
println!(
Expand Down
15 changes: 13 additions & 2 deletions examples/post_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ mod register;
use mastodon_async::{Language, Result, StatusBuilder, Visibility};

#[cfg(feature = "toml")]
#[tokio::main]
async fn main() -> Result<()> {
async fn run() -> Result<()> {
let mastodon = register::get_mastodon_data().await?;
let status = StatusBuilder::new()
.status(register::read_line(
Expand Down Expand Up @@ -34,6 +33,18 @@ async fn main() -> Result<()> {
Ok(())
}

#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
run().await
}

#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
run().await
}

#[cfg(not(feature = "toml"))]
fn main() {
println!(
Expand Down
15 changes: 13 additions & 2 deletions examples/print_your_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ mod register;
use mastodon_async::Result;

#[cfg(feature = "toml")]
#[tokio::main]
async fn main() -> Result<()> {
async fn run() -> Result<()> {
let mastodon = register::get_mastodon_data().await?;
let you = mastodon.verify_credentials().await?;

Expand All @@ -15,6 +14,18 @@ async fn main() -> Result<()> {
Ok(())
}

#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
run().await
}

#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
run().await
}

#[cfg(not(feature = "toml"))]
fn main() {
println!(
Expand Down
10 changes: 9 additions & 1 deletion examples/register/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ use mastodon_async::helpers::toml;
use mastodon_async::{helpers::cli, Result};

#[allow(dead_code)]
#[cfg(feature = "toml")]
#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
register().await?;
Ok(())
}

#[allow(dead_code)]
#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
register().await?;
Ok(())
}

#[allow(dead_code)]
#[cfg(feature = "toml")]
pub async fn get_mastodon_data() -> Result<Mastodon> {
Expand Down
15 changes: 13 additions & 2 deletions examples/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ mod register;
use mastodon_async::Result;

#[cfg(feature = "toml")]
#[tokio::main]
async fn main() -> Result<()> {
async fn run() -> Result<()> {
let mastodon = register::get_mastodon_data().await?;
let input = register::read_line("Enter the term you'd like to search: ")?;
let result = mastodon.search(&input, false).await?;
Expand All @@ -16,6 +15,18 @@ async fn main() -> Result<()> {
Ok(())
}

#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
run().await
}

#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
run().await
}

#[cfg(not(feature = "toml"))]
fn main() {
println!(
Expand Down
15 changes: 13 additions & 2 deletions examples/upload_photo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ mod register;
use mastodon_async::{Result, StatusBuilder, Visibility};

#[cfg(feature = "toml")]
#[tokio::main]
async fn main() -> Result<()> {
async fn run() -> Result<()> {
use register::bool_input;
femme::with_level(femme::LevelFilter::Trace);
let mastodon = register::get_mastodon_data().await?;
Expand Down Expand Up @@ -33,6 +32,18 @@ async fn main() -> Result<()> {
Ok(())
}

#[cfg(all(feature = "toml", feature = "mt"))]
#[tokio::main]
async fn main() -> Result<()> {
run().await
}

#[cfg(all(feature = "toml", not(feature = "mt")))]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
run().await
}

#[cfg(not(feature = "toml"))]
fn main() {
println!(
Expand Down

0 comments on commit f830671

Please sign in to comment.