/// Download region metadata and spawn page threads
Download region metadata and spawn page threads
Download region metadata and spawn page threads
fn download_region_market(region_id: RegionID,
                          client: esi::Client,
                          reschedule_channel: channel::Sender<(RegionID, DateTime<Utc>)>)
                          -> thread::JoinHandle<Result<store::TaggedOrderVec>> {
    thread::spawn(move || {
        // Todo: Retry
        let metadata = client.get_orders_metadata(region_id)?;
        // Re-schedule self with 3 second safety-margin
        reschedule_channel.send((region_id, metadata.expires + Duration::seconds(3)))
                          .unwrap();
        // Spawn threads for pages
        let mut page_handles: Vec<thread::JoinHandle<Result<Vec<Order>>>> = Vec::new();
        for page in 1..=metadata.pages {
            let handle = download_region_market_page(region_id, client.clone(), page);
            page_handles.push(handle);
        }
        // Collect results
        let mut orders: store::TaggedOrderVec = Vec::new();
        for handle in page_handles {
            // Unpack thread panic
            let thread_result = handle.join().unwrap();
            // Unpack thread result
            let pages = thread_result?;
            for order in pages {
                orders.push((order, metadata.last_modified));
            }
        }
        Ok(orders)
    })
}
fn download_region_market ( region_id : RegionID , client : esi :: Client , reschedule_channel : channel :: Sender < ( RegionID , DateTime < Utc > ) > ) -> thread :: JoinHandle < Result < store :: TaggedOrderVec > > { thread :: spawn ( move | | { // Todo: Retry let metadata = client . get_orders_metadata ( region_id ) ? ; // Re-schedule self with 3 second safety-margin reschedule_channel . send ( ( region_id , metadata . expires + Duration :: seconds ( 3 ) ) ) . unwrap ( ) ; // Spawn threads for pages let mut page_handles : Vec < thread :: JoinHandle < Result < Vec < Order > > > > = Vec :: new ( ) ; for page in 1 ..= metadata . pages { let handle = download_region_market_page ( region_id , client . clone ( ) , page ) ; page_handles . push ( handle ) ; } // Collect results let mut orders : store :: TaggedOrderVec = Vec :: new ( ) ; for handle in page_handles { // Unpack thread panic let thread_result = handle . join ( ) . unwrap ( ) ; // Unpack thread result let pages = thread_result ? ; for order in pages { orders . push ( ( order , metadata . last_modified ) ) ; } } Ok ( orders ) } ) }
Download region metadata and spawn page threads
Download region metadata and spawn page threads
region_id
RegionID
client
esi::Client
reschedule_channel
channel::Sender<(RegionID, DateTime<Utc>)>