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 failed computation resolution
|
2014-09-22 22:47:48 +02:00
|
|
|
*/
|
|
|
|
class Failure implements Promise {
|
|
|
|
private $error;
|
|
|
|
|
|
|
|
public function __construct(\Exception $error) {
|
|
|
|
$this->error = $error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass the resolved failure Exception to the specified callback
|
|
|
|
*
|
|
|
|
* NOTE: because this object represents a failed Promise it will *always* invoke the specified
|
|
|
|
* $func callback immediately.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function when(callable $func) {
|
|
|
|
$func($this->error, $result = null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does nothing -- a resolved promise has no progress updates
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function watch(callable $func) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|