Skip to content

Commit

Permalink
Add execution methods
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jun 1, 2017
1 parent e2b643c commit cb0ec9b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ public function getOptions():array {
return $this->options;
}

/**
* Executes all promises in parallel, returning only when all promises
* have been fulfilled.
*/
public function wait() {
$this->timer = $this->loop->addPeriodicTimer(
$this->interval,
[$this->requestResolver, "tick"]
);
$this->loop->run();
}

/**
* Begins execution of all promises, returning its own Promise that will
* resolve when the last HTTP request is fully resolved.
*/
public function all():Promise {
$deferred = new Deferred();
$promise = new Promise($deferred);
$this->wait();

$deferred->resolve(true);
return $promise;
}

/**
* Sends a PSR-7 request.
*
Expand Down

0 comments on commit cb0ec9b

Please sign in to comment.