6
6
use GuzzleHttp \Exception \RequestException ;
7
7
use function GuzzleHttp \Promise \coroutine ;
8
8
use GuzzleHttp \Promise \FulfilledPromise ;
9
+ use function GuzzleHttp \Promise \promise_for ;
9
10
use GuzzleHttp \Promise \PromiseInterface ;
10
11
use Markup \Contentful \Cache \NullCacheItemPool ;
11
12
use Markup \Contentful \Decorator \AssetDecoratorInterface ;
@@ -385,7 +386,6 @@ function () use ($spaceData, $spaceName, $endpointUrl, $exceptionMessage, $api,
385
386
return $ pool ->getItem ($ cacheKey );
386
387
};
387
388
$ assetDecorator = $ this ->ensureAssetDecorator ($ spaceData ['asset_decorator ' ]);
388
- $ finalPromise = null ;
389
389
/**
390
390
* Returns a built response if it passes test, or null if it doesn't.
391
391
*
@@ -430,8 +430,8 @@ function () use ($spaceData, $spaceName, $endpointUrl, $exceptionMessage, $api,
430
430
431
431
$ builtResponse = $ buildResponseFromJson ($ cacheItemJson );
432
432
if ($ builtResponse ) {
433
- $ finalPromise = new FulfilledPromise ($ builtResponse );
434
- goto finalYield ;
433
+ yield promise_for ($ builtResponse );
434
+ return ;
435
435
}
436
436
}
437
437
if ($ this ->cacheFailResponses ) {
@@ -449,8 +449,8 @@ function () use ($spaceData, $spaceName, $endpointUrl, $exceptionMessage, $api,
449
449
);
450
450
$ builtResponse = $ buildResponseFromJson ($ fallbackJson );
451
451
if ($ builtResponse ) {
452
- $ finalPromise = new FulfilledPromise ($ builtResponse );
453
- goto finalYield ;
452
+ yield promise_for ($ builtResponse );
453
+ return ;
454
454
}
455
455
}
456
456
}
@@ -499,22 +499,20 @@ function () use ($spaceData, $spaceName, $endpointUrl, $exceptionMessage, $api,
499
499
$ writeCacheItem ->set ($ fallbackJson );
500
500
$ writeCache ->save ($ writeCacheItem );
501
501
502
- $ finalPromise = new FulfilledPromise (
503
- $ this ->buildResponseFromRaw (
504
- json_decode ($ fallbackJson , true ),
505
- $ spaceData ['name ' ],
506
- $ assetDecorator ,
507
- $ shouldBuildTypedResources
508
- )
509
- );
510
- goto finalYield;
502
+ yield promise_for ($ this ->buildResponseFromRaw (
503
+ json_decode ($ fallbackJson , true ),
504
+ $ spaceData ['name ' ],
505
+ $ assetDecorator ,
506
+ $ shouldBuildTypedResources
507
+ ));
508
+ return ;
511
509
}
512
510
}
513
511
//if there is a rate limit error, wait (if applicable)
514
512
if ($ e ->hasResponse () && $ e ->getResponse ()->getStatusCode () === 429 && $ spaceData ['retry_time_after_rate_limit_in_ms ' ]) {
515
513
usleep (intval ($ spaceData ['retry_time_after_rate_limit_in_ms ' ]));
516
514
517
- $ finalPromise = ( yield $ this ->doRequest (
515
+ yield $ this ->doRequest (
518
516
$ spaceData ,
519
517
$ spaceName ,
520
518
$ endpointUrl ,
@@ -524,8 +522,8 @@ function () use ($spaceData, $spaceName, $endpointUrl, $exceptionMessage, $api,
524
522
$ cacheDisambiguator ,
525
523
$ parameters ,
526
524
array_merge ($ options , ['async ' => true ])
527
- )) ;
528
- goto finalYield ;
525
+ );
526
+ return ;
529
527
}
530
528
$ unavailableException = new ResourceUnavailableException ($ e ->getResponse (), $ exceptionMessage , 0 , $ e );
531
529
}
@@ -594,8 +592,8 @@ function () use ($spaceData, $spaceName, $endpointUrl, $exceptionMessage, $api,
594
592
);
595
593
$ builtResponse = $ buildResponseFromJson ($ fallbackJson );
596
594
if ($ builtResponse ) {
597
- $ finalPromise = new FulfilledPromise ($ builtResponse );
598
- goto finalYield ;
595
+ yield promise_for ($ builtResponse );
596
+ return ;
599
597
}
600
598
}
601
599
}
@@ -613,9 +611,7 @@ function () use ($spaceData, $spaceName, $endpointUrl, $exceptionMessage, $api,
613
611
LogInterface::TYPE_RESPONSE
614
612
);
615
613
616
- finalYield:
617
-
618
- yield $ finalPromise ?: new FulfilledPromise ($ builtResponse );
614
+ yield promise_for ($ builtResponse );
619
615
}
620
616
);
621
617
0 commit comments