mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-20 17:11:19 +02:00
feat: turn tokio-based async logic into futures
This commit is contained in:
11
src/lib.rs
11
src/lib.rs
@@ -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 {
|
||||
|
Reference in New Issue
Block a user