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

37 lines
834 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-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.
*/
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
}
/**
* Does nothing -- a resolved promise has no progress updates
*/
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
}
}