Use LazyPromise?
Closed this issue · 6 comments
public function __invoke(Message $message, Deferred $deferred = null):?Promise
{
$needReply = (bool) $deferred;
// stripped code.
if ($needReply) {
return new LazyPromise(function() use ($deferred, $reply) {
$value = JSON::decode($reply->receive($this->replyTimeout)->getBody());
try {
$deferred->resolve($value);
} catch (TimeoutException $e) {
$deferred->reject($e->getMessage());
}
});
}
But this is a BC an can only be done with a new major release.
for ref reactphp/promise#95
'''
(bool) $deferred;
'''
?
Added a comment in the linked reactphp issue. LazyPromise does not really help and the code above won't work I guess.
See the reactphp example of LazyPromise
The factory (callback passed to LazyPromise) needs to create its own deferred
and return the promise
of that deferred.
So you cannot resolve the deferred
injected by the query bus. But only the injected deferred has a connection to the promise returned by the query bus.
Can this be closed then?
issue is still discussed. Own LazyPromise
implementation could provide the wanted behavior. See linked reactphp issue
There is no possibility to set a custom promise to the deferred given as argument (the interface does not allow it). We could achieve what we want if prooph producer interface defines a promise as a return value. I guess the deferred could be removed in that case.
It is BC break though