1
0
mirror of https://github.com/danog/amp.git synced 2024-12-11 17:09:40 +01:00
amp/lib/Success.php

39 lines
790 B
PHP
Raw Normal View History

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.
*/
public function when(callable $func, $data = null) {
\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
*/
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
}
}