1
0
mirror of https://github.com/danog/amp.git synced 2024-12-15 02:47:30 +01:00
amp/lib/Failure.php

54 lines
1.2 KiB
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
/**
* Represents the failed resolution of a Promisor's future computation
*/
class Failure implements Promise {
private $error;
/**
* @param \Exception $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.
*
* @param callable $func
* @return void
*/
public function when(callable $func) {
$func($this->error, $result = null);
}
/**
* Does nothing -- a resolved promise has no progress updates
*
* @param callable $func
* @return void
*/
public function watch(callable $func) {
return;
}
/**
* Wait for Future value resolution
*
* NOTE: because this object represents a failed Promise it will *always* immediately throw the
* exception responsible for resolution failure.
*
* @throws \Exception
* @return void
*/
public function wait() {
throw $this->error;
}
}