File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change 77use Composer \Downloader \TransportException ;
88use Composer \Util \HttpDownloader ;
99use Composer \Util \Loop ;
10+ use React \Promise \Promise ;
1011use React \Promise \PromiseInterface ;
1112
1213readonly class Client
@@ -24,13 +25,8 @@ public function isClosed(string $slug): bool
2425 return false ;
2526 }
2627
27- $ cached = $ this ->cache ->read ($ slug );
28- if ($ cached !== null ) {
29- return $ cached ;
30- }
31-
3228 $ result = null ;
33- $ promise = $ this ->fetchAndCacheAsync ($ slug )
29+ $ promise = $ this ->isClosedAsync ($ slug )
3430 ->then (function (bool $ isClosed ) use (&$ result ): void {
3531 $ result = $ isClosed ;
3632 });
@@ -40,6 +36,19 @@ public function isClosed(string $slug): bool
4036 return $ result ;
4137 }
4238
39+ /**
40+ * @return PromiseInterface<bool>
41+ */
42+ private function isClosedAsync (string $ slug ): PromiseInterface
43+ {
44+ /** @var Promise<bool> */
45+ return new Promise (function (callable $ resolve ) use ($ slug ): void {
46+ $ cached = $ this ->cache ->read ($ slug );
47+ $ next = $ cached ?? $ this ->fetchAndCacheAsync ($ slug );
48+ $ resolve ($ next );
49+ });
50+ }
51+
4352 /**
4453 * @return PromiseInterface<bool>
4554 */
You can’t perform that action at this time.
0 commit comments