我正在尝试使用 ReactPHP 理解 Promises 的概念
$app = function ($request, $response) use ($redis, $config) {
$promise = React\Promise\all(
array(
AsyncGetUser(),
AsyncGetDB(),
AsyncGetTemplate()
)
)->then(function ($res) {
$result = ParseTemplate($user, $template, $whatever);
}
\React\Promise\resolve($promise);
$response->writeHead(200, array('Content-Type' => 'text/plain'));
$response->end($result);
}
$http->on('request', $app);
但在准备好$response
之前发送。$result
怎么能做类似等待的事情,$promise
所以我可以$result
正确发送?
我试图移动$response->end
到another->then()
部分,但是我没有在浏览器中得到任何响应(即脚本在 $app = function 已经完成时得到结果)。