1
0
mirror of https://github.com/danog/amp.git synced 2024-11-27 04:24:42 +01:00

Promisor::update() now accepts variadic args

This commit is contained in:
Daniel Lowrey 2015-03-19 11:26:56 -04:00
parent cd84401b6f
commit 68185a6cf1
3 changed files with 10 additions and 8 deletions

View File

@ -53,7 +53,7 @@ class Future implements Promisor, Promise {
* @throws \LogicException if the promise has already resolved
* @return void
*/
public function update($progress) {
public function update(...$progress) {
if ($this->isResolved) {
throw new \LogicException(
'Cannot update resolved promise'
@ -61,7 +61,7 @@ class Future implements Promisor, Promise {
}
foreach ($this->watchers as $watcher) {
$watcher($progress);
$watcher(...$progress);
}
}

View File

@ -16,10 +16,12 @@ class PrivateFuture implements Promisor {
public function __construct() {
$this->promise = new Unresolved;
$this->resolver = function(\Exception $error = null, $result = null) {
$this->resolve($error, $result); // bound to private Unresolved::resolve() at call-time
// bound to private Unresolved::resolve() at call-time
$this->resolve($error, $result);
};
$this->updater = function($progress) {
$this->update($progress); // bound to private Unresolved::update() at call-time
$this->updater = function(...$progress) {
// bound to private Unresolved::update() at call-time
$this->update(...$progress);
};
}
@ -36,8 +38,8 @@ class PrivateFuture implements Promisor {
* @param mixed $progress
* @return void
*/
public function update($progress) {
$this->updater->call($this->promise, $progress);
public function update(...$progress) {
$this->updater->call($this->promise, ...$progress);
}
/**

View File

@ -43,7 +43,7 @@ interface Promisor {
* @param mixed $progress
* @return void
*/
public function update($progress);
public function update(...$progress);
/**
* Resolve the promised value as a success