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-05-19 06:21:33 +02:00
|
|
|
* A placeholder value for the deferred result of an asynchronous computation
|
2014-09-22 22:47:48 +02:00
|
|
|
*/
|
|
|
|
interface Promise {
|
|
|
|
/**
|
2015-07-27 16:07:26 +02:00
|
|
|
* Notify the $cb callback when the promise resolves (whether successful or not)
|
2014-09-22 22:47:48 +02:00
|
|
|
*
|
2015-07-27 16:07:26 +02:00
|
|
|
* Implementations MUST invoke the $cb callback in error-first style, e.g.:
|
2014-09-22 22:47:48 +02:00
|
|
|
*
|
|
|
|
* <?php
|
|
|
|
* $promise->when(function(\Exception $error = null, $result = null) {
|
|
|
|
* if ($error) {
|
|
|
|
* // failed
|
|
|
|
* } else {
|
|
|
|
* // succeeded
|
|
|
|
* }
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* Implementations MUST return the current object instance.
|
|
|
|
*
|
2015-07-27 16:07:26 +02:00
|
|
|
* @param callable $cb An error-first callback to invoke upon promise resolution
|
|
|
|
* @param mixed $cbData Optional data to pass as a third parameter to $cb
|
2015-06-12 12:48:11 +02:00
|
|
|
* @return self
|
2014-09-22 22:47:48 +02:00
|
|
|
*/
|
2015-07-27 16:07:26 +02:00
|
|
|
public function when(callable $cb, $cbData = null);
|
2014-09-22 22:47:48 +02:00
|
|
|
|
|
|
|
/**
|
2015-07-27 16:07:26 +02:00
|
|
|
* Notify the $cb callback when resolution progress events are emitted
|
2014-09-22 22:47:48 +02:00
|
|
|
*
|
2015-07-27 16:07:26 +02:00
|
|
|
* Implementations MUST invoke $cb callback with a single update parameter, e.g.:
|
2014-09-22 22:47:48 +02:00
|
|
|
*
|
|
|
|
* <?php
|
|
|
|
* $promise->watch(function($update) { ... });
|
|
|
|
*
|
|
|
|
* Implementations MUST return the current object instance.
|
|
|
|
*
|
2015-07-27 16:07:26 +02:00
|
|
|
* @param callable $cb A callback to invoke when data updates are available
|
|
|
|
* @param mixed $cbData Optional data to pass as an additional parameter to $cb
|
2015-06-12 12:48:11 +02:00
|
|
|
* @return self
|
2014-09-22 22:47:48 +02:00
|
|
|
*/
|
2015-07-27 16:07:26 +02:00
|
|
|
public function watch(callable $cb, $cbData = null);
|
2014-09-22 22:47:48 +02:00
|
|
|
}
|