If used inside a single-threaded xp-forge/web web application, waiting will block the entire server. We should also have an asynchronous method to execute requests and wait for them.
Blocks server until API call returns
Current functionality
function($req, $res) use($endpoint) {
$user= $endpoint->resource('/users/me')->get()->value();
$res->answer(200);
$res->write('Hello '.$user['displayName'], 'text/plain');
}
Asynchronous handler function
Idea: Defer reading from request until any of RestResponse's methods are called, add await():
function($req, $res) use($endpoint) {
$user= (yield $endpoint->resource('/users/me')->get()->await())->value();
$res->answer(200);
$res->write('Hello '.$user['displayName'], 'text/plain');
}
If used inside a single-threaded
xp-forge/webweb application, waiting will block the entire server. We should also have an asynchronous method to execute requests and wait for them.Blocks server until API call returns
Current functionality
Asynchronous handler function
Idea: Defer reading from request until any of RestResponse's methods are called, add await():