Skip to content

Asynchronous invocation #25

Description

@thekid

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');
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions