pub fn read(&self, ids: Vec<&str>) -> Vec<Option<Post>> {
        // `firebase_rs`'s `.get_async` API is really dumb. It's forcing Arc and Mutex on us.
        let mut values: Vec<Arc<Mutex<Option<Post>>>> = vec![];
        let mut handles: Vec<Option<std::thread::JoinHandle<()>>> = vec![];
        for (i, id) in ids.iter().enumerate() {
            values.push(Arc::new(Mutex::new(None)));
            let item = values[i].clone();
            let maybe_node = self.at(&["posts", id]).ok();
            handles.push(maybe_node.map(|node| node.get_async(move |res| {
                let maybe_r = res.ok();
                let maybe_r = maybe_r.map(|r| from_str(&r.body).ok()).flatten();
                *item.lock().unwrap() = maybe_r;
            })));
        }
        for maybe_handle in handles { maybe_handle.map(|h| h.join().unwrap()); }
        values.drain(..).map(|mutex_ptr| {
            match Arc::try_unwrap(mutex_ptr).ok() {
                Some(mutex) => mutex.into_inner().unwrap(),
                None => None,
            }
        }).collect()
    }
/// Reads many posts from the database at once.
Reads many posts from the database at once.
Reads many posts from the database at once .
pub fn read(&self, ids: Vec<&str>) -> Vec<Option<Post>> {
        // `firebase_rs`'s `.get_async` API is really dumb. It's forcing Arc and Mutex on us.
        let mut values: Vec<Arc<Mutex<Option<Post>>>> = vec![];
        let mut handles: Vec<Option<std::thread::JoinHandle<()>>> = vec![];
        for (i, id) in ids.iter().enumerate() {
            values.push(Arc::new(Mutex::new(None)));
            let item = values[i].clone();
            let maybe_node = self.at(&["posts", id]).ok();
            handles.push(maybe_node.map(|node| node.get_async(move |res| {
                let maybe_r = res.ok();
                let maybe_r = maybe_r.map(|r| from_str(&r.body).ok()).flatten();
                *item.lock().unwrap() = maybe_r;
            })));
        }
        for maybe_handle in handles { maybe_handle.map(|h| h.join().unwrap()); }
        values.drain(..).map(|mutex_ptr| {
            match Arc::try_unwrap(mutex_ptr).ok() {
                Some(mutex) => mutex.into_inner().unwrap(),
                None => None,
            }
        }).collect()
    }
pub fn read ( & self , ids : Vec < & str > ) -> Vec < Option < Post > > { // `firebase_rs`'s `.get_async` API is really dumb. It's forcing Arc and Mutex on us. let mut values : Vec < Arc < Mutex < Option < Post > > > > = vec ! [ ] ; let mut handles : Vec < Option < std :: thread :: JoinHandle < ( ) > > > = vec ! [ ] ; for ( i , id ) in ids . iter ( ) . enumerate ( ) { values . push ( Arc :: new ( Mutex :: new ( None ) ) ) ; let item = values [ i ] . clone ( ) ; let maybe_node = self . at ( & [ " " , id ] ) . ok ( ) ; handles . push ( maybe_node . map ( | node | node . get_async ( move | res | { let maybe_r = res . ok ( ) ; let maybe_r = maybe_r . map ( | r | from_str ( & r . body ) . ok ( ) ) . flatten ( ) ; * item . lock ( ) . unwrap ( ) = maybe_r ; } ) ) ) ; } for maybe_handle in handles { maybe_handle . map ( | h | h . join ( ) . unwrap ( ) ) ; } values . drain ( .. ) . map ( | mutex_ptr | { match Arc :: try_unwrap ( mutex_ptr ) . ok ( ) { Some ( mutex ) => mutex . into_inner ( ) . unwrap ( ) , None => None , } } ) . collect ( ) }
Reads many posts from the database at once.
Reads many posts from the database at once .
&self
ids
Vec<&str>
&self
ids
Vec<&str>