2017-03-10 21:58:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Representation of the future value of an asynchronous operation.
|
|
|
|
*/
|
|
|
|
interface Promise {
|
|
|
|
/**
|
|
|
|
* Registers a callback to be invoked when the promise is resolved.
|
|
|
|
*
|
2018-03-25 17:27:41 +02:00
|
|
|
* If this method is called multiple times, additional handlers will be registered instead of replacing any already
|
|
|
|
* existing handlers.
|
|
|
|
*
|
2017-03-10 21:58:46 +01:00
|
|
|
* If the promise is already resolved, the callback MUST be executed immediately.
|
|
|
|
*
|
2017-06-06 19:57:03 +02:00
|
|
|
* Exceptions MUST NOT be thrown from this method. Any exceptions thrown from invoked callbacks MUST be
|
|
|
|
* forwarded to the event-loop error handler.
|
|
|
|
*
|
2018-03-25 17:27:41 +02:00
|
|
|
* Note: You shouldn't implement this interface yourself. Instead, provide a method that returns a promise for the
|
|
|
|
* operation you're implementing. Objects other than pure placeholders implementing it are a very bad idea.
|
|
|
|
*
|
2017-03-14 18:24:14 +01:00
|
|
|
* @param callable(\Throwable|null $reason, $value) $onResolved `$reason` shall be `null` on
|
2017-03-10 21:58:46 +01:00
|
|
|
* success, `$value` shall be `null` on failure.
|
|
|
|
*
|
2017-06-06 19:57:03 +02:00
|
|
|
* @return void
|
2017-03-10 21:58:46 +01:00
|
|
|
*/
|
2017-03-21 17:23:37 +01:00
|
|
|
public function onResolve(callable $onResolved);
|
2017-04-24 15:39:08 +02:00
|
|
|
}
|