pub async fn load_many<K>(
        &self,
        keys: impl Iterator<Item = K>,
    ) -> Result<HashMap<K, T::Value>, T::Error>
    where
        K: Send + Sync + Hash + Eq + Clone + 'static,
        T: Loader<K>,
    {
        let tid = TypeId::of::<K>();

        let (start_fetch, rx) = {
            let mut requests = self.requests.lock().await;
            let typed_requests = requests
                .entry(tid)
                .or_insert_with(|| Box::new(Requests::<K, T>::default()))
                .downcast_mut::<Requests<K, T>>()
                .unwrap();
            let prev_count = typed_requests.keys.len();
            let keys = keys.collect::<HashSet<_>>();
            typed_requests.keys.extend(keys.clone());
            let (tx, rx) = oneshot::channel();
            typed_requests.pending.push((keys, ResSender(tx)));
            if typed_requests.keys.len() >= self.max_batch_size {
                let r = std::mem::take(&mut *typed_requests);
                drop(requests);
                r.load(&self.loader).await;
                (false, rx)
            } else {
                (!typed_requests.keys.is_empty() && prev_count == 0, rx)
            }
        };

        if start_fetch {
            Delay::new(self.delay).await;
            let mut requests = self.requests.lock().await;
            let typed_requests = requests
                .get_mut(&tid)
                .unwrap()
                .downcast_mut::<Requests<K, T>>()
                .unwrap();
            let typed_requests = std::mem::take(typed_requests);
            drop(requests);
            if !typed_requests.keys.is_empty() {
                typed_requests.load(&self.loader).await;
            }
        }

        rx.await.unwrap()
    }
/// Use this `DataLoader` to load some data.
Use this `DataLoader` to load some data.
Use this ` DataLoader ` to load some data .
pub async fn load_many<K>(
        &self,
        keys: impl Iterator<Item = K>,
    ) -> Result<HashMap<K, T::Value>, T::Error>
    where
        K: Send + Sync + Hash + Eq + Clone + 'static,
        T: Loader<K>,
    {
        let tid = TypeId::of::<K>();
        let (start_fetch, rx) = {
            let mut requests = self.requests.lock().await;
            let typed_requests = requests
                .entry(tid)
                .or_insert_with(|| Box::new(Requests::<K, T>::default()))
                .downcast_mut::<Requests<K, T>>()
                .unwrap();
            let prev_count = typed_requests.keys.len();
            let keys = keys.collect::<HashSet<_>>();
            typed_requests.keys.extend(keys.clone());
            let (tx, rx) = oneshot::channel();
            typed_requests.pending.push((keys, ResSender(tx)));
            if typed_requests.keys.len() >= self.max_batch_size {
                let r = std::mem::take(&mut *typed_requests);
                drop(requests);
                r.load(&self.loader).await;
                (false, rx)
            } else {
                (!typed_requests.keys.is_empty() && prev_count == 0, rx)
            }
        };
        if start_fetch {
            Delay::new(self.delay).await;
            let mut requests = self.requests.lock().await;
            let typed_requests = requests
                .get_mut(&tid)
                .unwrap()
                .downcast_mut::<Requests<K, T>>()
                .unwrap();
            let typed_requests = std::mem::take(typed_requests);
            drop(requests);
            if !typed_requests.keys.is_empty() {
                typed_requests.load(&self.loader).await;
            }
        }
        rx.await.unwrap()
    }
pub async fn load_many < K > ( & self , keys : impl Iterator < Item = K > , ) -> Result < HashMap < K , T :: Value > , T :: Error > where K : Send + Sync + Hash + Eq + Clone + ' static , T : Loader < K > , { let tid = TypeId :: of :: < K > ( ) ; let ( start_fetch , rx ) = { let mut requests = self . requests . lock ( ) . await ; let typed_requests = requests . entry ( tid ) . or_insert_with ( | | Box :: new ( Requests :: < K , T > :: default ( ) ) ) . downcast_mut :: < Requests < K , T > > ( ) . unwrap ( ) ; let prev_count = typed_requests . keys . len ( ) ; let keys = keys . collect :: < HashSet < _ > > ( ) ; typed_requests . keys . extend ( keys . clone ( ) ) ; let ( tx , rx ) = oneshot :: channel ( ) ; typed_requests . pending . push ( ( keys , ResSender ( tx ) ) ) ; if typed_requests . keys . len ( ) >= self . max_batch_size { let r = std :: mem :: take ( & mut * typed_requests ) ; drop ( requests ) ; r . load ( & self . loader ) . await ; ( false , rx ) } else { ( ! typed_requests . keys . is_empty ( ) && prev_count == 0 , rx ) } } ; if start_fetch { Delay :: new ( self . delay ) . await ; let mut requests = self . requests . lock ( ) . await ; let typed_requests = requests . get_mut ( & tid ) . unwrap ( ) . downcast_mut :: < Requests < K , T > > ( ) . unwrap ( ) ; let typed_requests = std :: mem :: take ( typed_requests ) ; drop ( requests ) ; if ! typed_requests . keys . is_empty ( ) { typed_requests . load ( & self . loader ) . await ; } } rx . await . unwrap ( ) }
Use this `DataLoader` to load some data.
Use this ` DataLoader ` to load some data .
&self
keys
impl Iterator<Item = K>
&self
keys
impl Iterator<Item = K>