2014-09-22 22:47:48 +02:00
|
|
|
<?php
|
|
|
|
|
2014-09-23 04:38:32 +02:00
|
|
|
namespace Amp;
|
2014-09-22 22:47:48 +02:00
|
|
|
|
|
|
|
/**
|
2015-03-19 16:14:21 +01:00
|
|
|
* Represents a successful computation resolution
|
2014-09-22 22:47:48 +02:00
|
|
|
*/
|
|
|
|
class Success implements Promise {
|
|
|
|
private $result;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $result
|
|
|
|
*/
|
|
|
|
public function __construct($result = null) {
|
|
|
|
$this->result = $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass the resolved result to the specified $func callback
|
|
|
|
*
|
|
|
|
* NOTE: because this object represents a successfully resolved Promise it will *always* invoke
|
|
|
|
* the specified $func callback immediately.
|
|
|
|
*/
|
2015-05-20 00:49:08 +02:00
|
|
|
public function when(callable $func, $data = null) {
|
2015-06-12 12:48:11 +02:00
|
|
|
\call_user_func($func, $error = null, $this->result, $data);
|
|
|
|
|
2015-03-19 16:14:21 +01:00
|
|
|
return $this;
|
2014-09-22 22:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does nothing -- a resolved promise has no progress updates
|
|
|
|
*/
|
2015-05-20 00:49:08 +02:00
|
|
|
public function watch(callable $func, $data = null) {
|
2015-03-19 16:14:21 +01:00
|
|
|
return $this;
|
2014-09-22 22:47:48 +02:00
|
|
|
}
|
|
|
|
}
|