mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 09:31: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;
|
use futures::StreamExt;
|
||||||
|
|
||||||
|
const DEFAULT_RATE_LIMIT: usize = 4;
|
||||||
|
|
||||||
/// This is where the magic happens
|
/// This is where the magic happens
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn run(config: Config) {
|
pub async fn run(config: Config) {
|
||||||
@@ -52,8 +54,8 @@ pub async fn run(config: Config) {
|
|||||||
|
|
||||||
// retrieve the last tweet ID for the username
|
// retrieve the last tweet ID for the username
|
||||||
let lconn = task_conn.lock().await;
|
let lconn = task_conn.lock().await;
|
||||||
let last_tweet_id =
|
let last_tweet_id = read_state(&lconn, &mastodon_config.twitter_screen_name, None)?
|
||||||
read_state(&lconn, &mastodon_config.twitter_screen_name, None)?.map(|r| r.tweet_id);
|
.map(|r| r.tweet_id);
|
||||||
drop(lconn);
|
drop(lconn);
|
||||||
|
|
||||||
// get user timeline feed (Vec<tweet>)
|
// get user timeline feed (Vec<tweet>)
|
||||||
@@ -137,8 +139,9 @@ pub async fn run(config: Config) {
|
|||||||
drop(lconn);
|
drop(lconn);
|
||||||
}
|
}
|
||||||
Ok::<(), ScootalooError>(())
|
Ok::<(), ScootalooError>(())
|
||||||
});
|
})
|
||||||
}).buffer_unordered(4);
|
})
|
||||||
|
.buffer_unordered(config.scootaloo.rate_limit.unwrap_or(DEFAULT_RATE_LIMIT));
|
||||||
|
|
||||||
// launch and wait for every handle
|
// launch and wait for every handle
|
||||||
while let Some(result) = stream.next().await {
|
while let Some(result) = stream.next().await {
|
||||||
|
Reference in New Issue
Block a user