1
0
mirror of https://github.com/danog/amp.git synced 2024-12-15 19:07:22 +01:00
amp/lib/Success.php

39 lines
788 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
* the specified $cb callback immediately.
2014-09-22 22:47:48 +02:00
*/
public function when(callable $cb, $cbData = null) {
\call_user_func($cb, $error = null, $this->result, $cbData);
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 $cb, $cbData = null) {
2015-03-19 16:14:21 +01:00
return $this;
2014-09-22 22:47:48 +02:00
}
}