I am performing an RPC call over MQ. and I'd like to return the control to the code that invoked my method. The $reply->receive() call must be postponed as long as possible. It is blokcing operation and it returns the result. I cannot call $deferred->resolve immidiatly so I am thinking of doing something with LazyPromise. Something like this:
<?php
public function __invoke(Message $message, Deferred $deferred = null):Promise
{
// do some stuff which results in $reply var.
return new LazyPromise(function() use ($deferred, $reply) {
try {
$value = JSON::decode($reply->receive($this->replyTimeout)->getBody());
$deferred->resolve($value);
} catch (TimeoutException $e) {
$deferred->reject($e->getMessage());
}
return $deferred->promise();
});
}
Is this the right way to go? Is there a better solution?
I am performing an RPC call over MQ. and I'd like to return the control to the code that invoked my method. The
$reply->receive()call must be postponed as long as possible. It is blokcing operation and it returns the result. I cannot call $deferred->resolve immidiatly so I am thinking of doing something with LazyPromise. Something like this:Is this the right way to go? Is there a better solution?