feat: turn tokio-based async logic into futures

This commit is contained in:
VC
2022-11-15 09:34:05 +01:00
parent f371b8a297
commit 7f7219ea78

View File

@@ -27,6 +27,8 @@ use tokio::{spawn, sync::Mutex};
use futures::StreamExt;
const DEFAULT_RATE_LIMIT: usize = 4;
/// This is where the magic happens
#[tokio::main]
pub async fn run(config: Config) {
@@ -52,8 +54,8 @@ pub async fn run(config: Config) {
// retrieve the last tweet ID for the username
let lconn = task_conn.lock().await;
let last_tweet_id =
read_state(&lconn, &mastodon_config.twitter_screen_name, None)?.map(|r| r.tweet_id);
let last_tweet_id = read_state(&lconn, &mastodon_config.twitter_screen_name, None)?
.map(|r| r.tweet_id);
drop(lconn);
// get user timeline feed (Vec<tweet>)
@@ -137,8 +139,9 @@ pub async fn run(config: Config) {
drop(lconn);
}
Ok::<(), ScootalooError>(())
});
}).buffer_unordered(4);
})
})
.buffer_unordered(config.scootaloo.rate_limit.unwrap_or(DEFAULT_RATE_LIMIT));
// launch and wait for every handle
while let Some(result) = stream.next().await {