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-07-21 04:24:51 +02:00
|
|
|
* A successfully resolved promise
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-21 04:24:51 +02:00
|
|
|
* {@inheritdoc}
|
2014-09-22 22:47:48 +02:00
|
|
|
*
|
2015-07-21 04:24:51 +02:00
|
|
|
* NOTE: because this object represents a resolved Promise it will *always* invoke
|
2014-09-22 22:47:48 +02:00
|
|
|
* 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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-21 04:24:51 +02:00
|
|
|
* {@inheritdoc}
|
|
|
|
*
|
|
|
|
* Does nothing; a resolved promise has no progress updates
|
2014-09-22 22:47:48 +02:00
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
}
|