use async_std::{ stream::{Stream, StreamExt}, task, }; use autopool::{AutoPool, AutoPoolConfig, Job, JobStatus, WorkerPool, WorkerPoolConfig}; use log::warn; use std::time::Duration; use surf::{self, Error, Response}; fn main() { task::block_on(async { let worker_pool_config = *WorkerPoolConfig::new().default_job("http://google.com"); let auto_pool_config = AutoPoolConfig::new(Duration::from_secs_f32(0.1), 2500.0); let worker_pool = WorkerPool::new_with_config(load_url_forever, worker_pool_config); let mut auto_pool = AutoPool::new(auto_pool_config, worker_pool); for _ in 0..10 { let x = auto_pool.next().await; dbg!(x); } }); } /// Double the input some number of times or until we receive a close message async fn load_url_forever(job: Job<&'static str, usize>) -> JobStatus { loop { if job.stop_requested() { return JobStatus::Stopped; } let url = job.task; match surf::get(url).await { Ok(res) => { job.results.send(res.status() as usize).await; } Err(e) => { warn!("{}", e); } } } }