-
Hi All i'm using this:
to get the streamed results of a server. But if there's an issue like ports blocked, IP blocked, or server down, I want to be able to test for and respond to this based on the timeout I receive in the function Exception
BUT i can't currently do this because its all in a promise and doesn't get sorted until the promise is resolved on an await. await(first($stream, 'data'))) is it possible to test the connection when setting it up with
without having to execute / resolve the promise it relates to? To clarify, I know how to catch errors within the response, and how to catch errors with $stream->on('error',()=>{}). But once the errors are caught this far down the process, the promise is already resolving, and it's not really possible to intercept with a validation / error approach, like trying to restart the server or changing to different port and then recursively kicking off the client request a second time. ie. All the existing error catching, relies on the promise resolving, so none of it is triggered until after the promise is in play, which makes it impossible to 'intercept' and unpack while in flight. Any ideas? Cheers |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @clue Just to make it a bit clearer what I'm attempting.. and why it's been a bit of an issue:
However, the existing stream is still technically running therefore all the code is run when the promise being called.. at the very end of the code using: await(first($stream, 'data')), and it seems it's not technically possible to call or change the direction of the promise from within the promise and dynamically modifying itself or stopping itself midway to re-kickoff the entire process again after having restarted the server. This is where promises do my head in a bit. At first I though I could simply 'escape' the function on this error and kick off the steps again. But seems this is not possible from within the promise - it's all packed like a suitcase. *** I suspect maybe I need to try-catch the server errors at the point of calling the promise - on the await(first($stream, 'data')).. but i hope not - it's a bit hacky. *** I get this error: Message: An error occured on the underlying stream while waiting for event: Not a readable stream Filename: C:\xampp81\php\vendor\react\promise-stream\src\functions.php Line Number: 152 Backtrace: File: C:\xampp81\php\vendor\evenement\evenement\src\EventEmitterTrait.php File: C:\xampp81\php\vendor\react\promise-stream\src\UnwrapReadableStream.php File: C:\xampp81\php\vendor\react\promise\src\Internal\RejectedPromise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Internal\RejectedPromise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Internal\FulfilledPromise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Deferred.php File: C:\xampp81\php\vendor\react\http\src\Io\Transaction.php File: C:\xampp81\php\vendor\react\promise\src\Internal\RejectedPromise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Internal\RejectedPromise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Deferred.php File: C:\xampp81\php\vendor\react\http\src\Io\Sender.php File: C:\xampp81\php\vendor\evenement\evenement\src\EventEmitterTrait.php File: C:\xampp81\php\vendor\react\http\src\Io\ClientRequestStream.php File: C:\xampp81\php\vendor\react\promise\src\Internal\RejectedPromise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\promise\src\Promise.php File: C:\xampp81\php\vendor\react\socket\src\TimeoutConnector.php File: C:\xampp81\php\vendor\react\event-loop\src\Timer\Timers.php File: C:\xampp81\php\vendor\react\event-loop\src\StreamSelectLoop.php File: C:\xampp81\php\vendor\react\event-loop\src\Loop.php File: C:\xampp81\php\vendor\react\async\src\SimpleFiber.php File: C:\xampp81\php\vendor\react\async\src\SimpleFiber.php File: C:\xampp81\php\vendor\react\async\src\functions.php File: C:\xampp81\htdocs\villg.life\application\helpers\sockethttpclientservers_helper.php File: C:\xampp81\htdocs\villg.life\application\controllers\lead\LocalServerController.php |
Beta Was this translation helpful? Give feedback.
-
Solved.. I have to run the checks using a try-catch on the promise resolve / await.. which means I need to throw an exception from the validation tests inside the stream function, I've got it working - but not the prettiest approach. Cheers |
Beta Was this translation helpful? Give feedback.
Solved..
I have to run the checks using a try-catch on the promise resolve / await..
which means I need to throw an exception from the validation tests inside the stream function,
I've got it working - but not the prettiest approach.
Cheers