Hi all, my struct WeatherStream seems to not find its own method called fetch_thousand
Here is the context and also the error that I get below:
struct WeatherStream<S, I>
where
S: StoreWeather,
I: Iterator,
{
uri_iter: I,
interval: Interval,
fetch_future: Option<Box<Future<Item = (), Error = ()> + 'static + Send>>,
storage_client: Arc<Mutex<Box<S>>>,
time_pass: TimePass,
}
impl<S, I> WeatherStream<S, I>
where
S: StoreWeather,
I: Iterator<Item = Uri>,
{
fn new(uri_iter: I, duration: Duration, storage_client: S) -> Self {
Self {
uri_iter,
interval: Interval::new_interval(duration),
fetch_future: None,
storage_client: Arc::new(Mutex::new(Box::new(storage_client))),
time_pass: TimePass::Ready,
}
}
//change number of requests to a parameter.
pub fn fetch_thousand(&mut self) -> impl Future<Item = bool, Error = ()> {
let uri = match self.uri_iter.next() {
Some(u) => Arc::new(u),
None => return future::ok::<bool, ()>(false),
};
let client = build_https_client().unwrap(); //TODO catch error
let requests: Vec<_> = (0..1000)
.zip(self.uri_iter) //make a zip with iterator
.map(move |(_, uri)| {
client
.clone()
.get(uri)
.map(|res| {
println!("Response: {}", res.status());
println!("Headers: {:#?}", res.headers());
})
.map_err(|e| println!("{:?}", e))
})
.collect();
future::join_all(requests)
.map(|_| return future::ok::<bool, ()>(true))
.map_err(|_| return future::err::<bool, ()>(()));
return future::ok::<bool, ()>(false)
}
}
impl<S, I> Stream for WeatherStream<S, I>
where
S: StoreWeather + 'static,
I: Iterator + 'static,
{
type Item = bool;
type Error = ();
fn poll(&mut self) -> Poll<Option<Self::Item>, ()> {
loop {
match self.time_pass {
TimePass::Ready => {
if let Some(_) = self.fetch_future {
try_ready!(self.fetch_future.poll().map_err(|_| ()));
} else {
self.fetch_future = Some(Box::new(self.fetch_thousand()));
try_ready!(self.fetch_future.poll().map_err(|_| ()));
}
self.time_pass = TimePass::Waiting;
self.fetch_future = None;
}
TimePass::Waiting => {
//TODO do a peak on iter to not waste a day of waiting at end.
match self.interval.poll() {
Ok(Async::Ready(value)) => {
self.time_pass = TimePass::Ready;
return Ok(Async::Ready(Some(false)));
}
Ok(Async::NotReady) => return Ok(Async::NotReady),
Err(err) => return Err(()),
}
}
};
}
}
}
error[E0599]: no method named `fetch_thousand` found for type `&mut fetch::fetch_job::WeatherStream<S, I>` in the current scope
--> src/fetch/fetch_job.rs:125:64
|
125 | self.fetch_future = Some(Box::new(self.fetch_thousand()));
| ^^^^^^^^^^^^^^
I have no clue what is going on here.