File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -263,6 +263,11 @@ private static function awaitInstances()
263263 $ dataLoader ->process ();
264264 }
265265 }
266+
267+ // If new dataloaders were instanciated in the meantime, wait again !
268+ if (count ($ dataLoaders ) != count (self ::$ instances )) {
269+ self ::awaitInstances ();
270+ }
266271 }
267272
268273 private function getCacheKeyFromKey ($ key )
Original file line number Diff line number Diff line change @@ -786,6 +786,29 @@ public function testCallingAwaitFunctionWhenNoInstanceOfDataLoaderShouldNotThrow
786786 DataLoader::await ();
787787 }
788788
789+ public function testAwaitAlsoAwaitsNewlyCreatedDataloaders ()
790+ {
791+ $ firstComplete = false ;
792+ $ secondComplete = false ;
793+
794+ $ first = new DataLoader (function ($ values ) use (&$ firstComplete , &$ secondComplete ) {
795+ $ second = new DataLoader (function ($ values ) use (&$ secondComplete ) {
796+ $ secondComplete = true ;
797+ return self ::$ promiseFactory ->createAll (['B ' ]);
798+ }, self ::$ promiseFactory );
799+
800+ $ second ->load ('B ' );
801+
802+ $ firstComplete = true ;
803+ return self ::$ promiseFactory ->createAll (['A ' ]);
804+ }, self ::$ promiseFactory );
805+
806+ DataLoader::await ($ first ->load ('A ' ));
807+
808+ $ this ->assertTrue ($ firstComplete );
809+ $ this ->assertTrue ($ secondComplete );
810+ }
811+
789812 public function cacheKey ($ key )
790813 {
791814 $ cacheKey = [];
You can’t perform that action at this time.
0 commit comments