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:
parent
cd84401b6f
commit
68185a6cf1
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user