@@ -224,7 +224,7 @@ impl<
224224 Q : Hash + Equivalent < Key > + ToOwned < Owned = Key > + ?Sized ,
225225 {
226226 let mut shard_guard = shard. write ( ) ;
227- let shared = match shard_guard. upsert_placeholder ( hash, key) {
227+ let shared = match shard_guard. upsert_placeholder ( hash, key, & mut |_| true ) {
228228 Ok ( ( _, v) ) => return GuardResult :: Value ( v. clone ( ) ) ,
229229 Err ( ( shared, true ) ) => {
230230 return GuardResult :: Guard ( Self :: start_loading ( lifecycle, shard, shared) ) ;
@@ -413,11 +413,12 @@ impl<Key, Val, We, B, L> std::fmt::Debug for PlaceholderGuard<'_, Key, Val, We,
413413}
414414
415415/// Future that results in an Ok(Value) or Err(Guard)
416- pub struct JoinFuture < ' a , ' b , Q : ?Sized , Key , Val , We , B , L > {
416+ pub struct JoinFuture < ' a , ' b , Q : ?Sized , Key , Val , We , B , L , F : FnMut ( & ' a Val ) -> bool > {
417417 lifecycle : & ' a L ,
418418 shard : & ' a RwLock < CacheShard < Key , Val , We , B , L , SharedPlaceholder < Val > > > ,
419419 state : JoinFutureState < ' b , Q , Val > ,
420420 notified : AtomicBool ,
421+ validation : F ,
421422}
422423
423424enum JoinFutureState < ' b , Q : ?Sized , Val > {
@@ -432,18 +433,22 @@ enum JoinFutureState<'b, Q: ?Sized, Val> {
432433 Done ,
433434}
434435
435- impl < ' a , ' b , Q : ?Sized , Key , Val , We , B , L > JoinFuture < ' a , ' b , Q , Key , Val , We , B , L > {
436+ impl < ' a , ' b , Q : ?Sized , Key , Val , We , B , L , F : FnMut ( & ' a Val ) -> bool >
437+ JoinFuture < ' a , ' b , Q , Key , Val , We , B , L , F >
438+ {
436439 pub fn new (
437440 lifecycle : & ' a L ,
438441 shard : & ' a RwLock < CacheShard < Key , Val , We , B , L , SharedPlaceholder < Val > > > ,
439442 hash : u64 ,
440443 key : & ' b Q ,
441- ) -> JoinFuture < ' a , ' b , Q , Key , Val , We , B , L > {
444+ validation : F ,
445+ ) -> JoinFuture < ' a , ' b , Q , Key , Val , We , B , L , F > {
442446 Self {
443447 lifecycle,
444448 shard,
445449 state : JoinFutureState :: Created { hash, key } ,
446450 notified : Default :: default ( ) ,
451+ validation,
447452 }
448453 }
449454
@@ -480,7 +485,10 @@ impl<'a, 'b, Q: ?Sized, Key, Val, We, B, L> JoinFuture<'a, 'b, Q, Key, Val, We,
480485 }
481486}
482487
483- impl < Q : ?Sized , Key , Val , We , B , L > Drop for JoinFuture < ' _ , ' _ , Q , Key , Val , We , B , L > {
488+ impl < ' a , Q : ?Sized , Key , Val , We , B , L , F > Drop for JoinFuture < ' a , ' _ , Q , Key , Val , We , B , L , F >
489+ where
490+ F : FnMut ( & ' a Val ) -> bool ,
491+ {
484492 #[ inline]
485493 fn drop ( & mut self ) {
486494 if matches ! ( self . state, JoinFutureState :: Pending { .. } ) {
@@ -497,7 +505,8 @@ impl<
497505 We : Weighter < Key , Val > ,
498506 B : BuildHasher ,
499507 L : Lifecycle < Key , Val > ,
500- > Future for JoinFuture < ' a , ' _ , Q , Key , Val , We , B , L >
508+ F : FnMut ( & Val ) -> bool + Unpin ,
509+ > Future for JoinFuture < ' a , ' _ , Q , Key , Val , We , B , L , F >
501510{
502511 type Output = Result < Val , PlaceholderGuard < ' a , Key , Val , We , B , L > > ;
503512
@@ -509,7 +518,7 @@ impl<
509518 JoinFutureState :: Created { hash, key } => {
510519 debug_assert ! ( !this. notified. load( Ordering :: Acquire ) ) ;
511520 let mut shard_guard = shard. write ( ) ;
512- match shard_guard. upsert_placeholder ( * hash, * key) {
521+ match shard_guard. upsert_placeholder ( * hash, * key, & mut this . validation ) {
513522 Ok ( ( _, v) ) => {
514523 this. state = JoinFutureState :: Done ;
515524 Poll :: Ready ( Ok ( v. clone ( ) ) )
0 commit comments