@@ -87,6 +87,13 @@ class PendingRequest implements PendingRequestContract
8787 */
8888 protected ?SimulatedResponsePayload $ simulatedResponsePayload = null ;
8989
90+ /**
91+ * Determine if the pending request is asynchronous
92+ *
93+ * @var bool
94+ */
95+ protected bool $ asynchronous = false ;
96+
9097 /**
9198 * Build up the request payload.
9299 *
@@ -436,6 +443,8 @@ protected function resolveResponseClass(): string
436443 */
437444 public function send (): ResponseContract
438445 {
446+ $ this ->setAsynchronous (false );
447+
439448 return (new Dispatcher ($ this ))->execute ();
440449 }
441450
@@ -446,7 +455,9 @@ public function send(): ResponseContract
446455 */
447456 public function sendAsync (): PromiseInterface
448457 {
449- return (new Dispatcher ($ this , true ))->execute ();
458+ $ this ->setAsynchronous (true );
459+
460+ return (new Dispatcher ($ this ))->execute ();
450461 }
451462
452463 /**
@@ -459,4 +470,27 @@ public function createDtoFromResponse(ResponseContract $response): mixed
459470 {
460471 return $ this ->request ->createDtoFromResponse ($ response ) ?? $ this ->connector ->createDtoFromResponse ($ response );
461472 }
473+
474+ /**
475+ * Set if the request is going to be sent asynchronously
476+ *
477+ * @param bool $asynchronous
478+ * @return PendingRequestContract
479+ */
480+ public function setAsynchronous (bool $ asynchronous ): static
481+ {
482+ $ this ->asynchronous = $ asynchronous ;
483+
484+ return $ this ;
485+ }
486+
487+ /**
488+ * Check if the request is asynchronous
489+ *
490+ * @return bool
491+ */
492+ public function isAsynchronous (): bool
493+ {
494+ return $ this ->asynchronous ;
495+ }
462496}
0 commit comments