-
-
Notifications
You must be signed in to change notification settings - Fork 150
Implement JsonSerializable #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
when beeing part of e.g. array the FullfilledPromise is not serialized, this will return the value now
|
Hi @simonbuehler, thanks for taking the time to file this PR! 👍 Unfortunately, the PR does not contain any documentation or tests, so it's a bit unclear what you're trying to achieve from the changeset you've posted. I don't think this piece of code should live in the promise implementation, but I'm curious to get a better understanding of the problem you're trying to solve. May I ask you provide a simple gist of what you're trying to achieve? Thanks! |
|
hi, sorry for the barebone commit, i just fixed a problem i came across when returning an object in laravel that had a nested FulfilledPromise in it and after serializing the value was lost. the image shows a laravel dump of the object on serverside and below is the returned http response after going through the serialisation the call to json_encode was the problem i fixed along the way, please let me know what would be a better way to accomplish this |
|
Ok but why is the promise being JSON encoded? When you get a promise you don't know it has resolved yet until your handlers are called. You might just as easy end up with a pending promise and a null value. I also agree with @clue that this code has no place in this project, and would even create the wrong idea of what this package does. So I rather focus on understanding what you're trying to do and help you resolve that. |
|
in my understanding its the right place as its in the
|
|
for the context: im using the LaravelWebSockets server which is based on Ratchet and Reactphp - inside a API handler i prepare the websocket user data together with the sockets along those lines: public function __invoke(Request $request)
{
return $this->channelManager
->getChannelMembers($request->appId, $request->channelName)
->then(function ($members) use ($request) {
$users = collect($members)->map(function ($user) use ($request) {
$user->sockets = $this->channelManager->getMemberSockets($user->user_id, $request->appId, $request->channelName)
->then(function ($sockets) {
return $sockets; //resolved
});
return $user; //resolved
})->values()->toArray();
dump($users); //resolved - with sockets
return [
'users' => $users
];
});
}then the laravel magic returns the result to the http caller in |
|
Try this: public function __invoke(Request $request)
{
return $this->channelManager
->getChannelMembers($request->appId, $request->channelName)
->then(function ($members) use ($request) {
return \React\Promise\all([
'users' => \React\Promise\all(collect($members)->map(function ($user) use ($request) {
$this->channelManager->getMemberSockets($user->user_id, $request->appId, $request->channelName)
->then(function ($sockets) use ($user) {
$user->sockets = $sockets; //resolved
return $user;
});
return $user; //resolved
})->values()->toArray())
];
});
} |
|
wow 🙌 its works and is so elegant - but i also have to let it sink in a while! Thanks for the input guys! |

when beeing part of e.g. array the FullfilledPromise is not serialized, this will return the value now