1
0
mirror of https://github.com/danog/amp.git synced 2024-12-11 17:09:40 +01:00
amp/lib/Promise.php

38 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace Amp;
/**
* Representation of the future value of an asynchronous operation.
*
* @template-covariant TValue
* @psalm-yield TValue
*/
2020-09-24 18:52:22 +02:00
interface Promise extends \Awaitable
2018-06-18 20:00:01 +02:00
{
/**
* 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.
*
* 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.
*
* @param callable $onResolved The first argument shall be `null` on success, while the second shall be `null` on
* failure.
*
* @psalm-param callable(\Throwable|null, mixed): (Promise|\React\Promise\PromiseInterface|\Generator<mixed,
* Promise|\React\Promise\PromiseInterface|array<array-key, Promise|\React\Promise\PromiseInterface>, mixed,
* mixed>|null) | callable(\Throwable|null, mixed): void $onResolved
2020-03-21 21:15:39 +01:00
*
* @return void
*/
2020-09-24 18:52:22 +02:00
public function onResolve(callable $onResolved): void;
}