1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 21:31:18 +01:00
amp/lib/Promise.php

47 lines
1.4 KiB
PHP
Raw Normal View History

2014-09-22 16:47:48 -04:00
<?php
2014-09-22 22:38:32 -04:00
namespace Amp;
2014-09-22 16:47:48 -04:00
/**
2015-05-19 00:21:33 -04:00
* A placeholder value for the deferred result of an asynchronous computation
2014-09-22 16:47:48 -04:00
*/
interface Promise {
/**
* Notify the $func callback when the promise resolves (whether successful or not)
*
* Implementations MUST invoke the $func callback in error-first style, e.g.:
*
* <?php
* $promise->when(function(\Exception $error = null, $result = null) {
* if ($error) {
* // failed
* } else {
* // succeeded
* }
* });
*
* Implementations MUST return the current object instance.
*
* @param callable $func An error-first callback to invoke upon promise resolution
* @param mixed $data Optional data to pass as a third parameter to $func
2015-03-19 11:14:21 -04:00
* @return void
2014-09-22 16:47:48 -04:00
*/
public function when(callable $func, $data = null);
2014-09-22 16:47:48 -04:00
/**
* Notify the $func callback when resolution progress events are emitted
*
* Implementations MUST invoke $func callback with a single update parameter, e.g.:
*
* <?php
* $promise->watch(function($update) { ... });
*
* Implementations MUST return the current object instance.
*
* @param callable $func A callback to invoke when data updates are available
2015-05-31 19:51:09 -04:00
* @param mixed $data Optional data to pass as an additional parameter to $func
2015-03-19 11:14:21 -04:00
* @return void
2014-09-22 16:47:48 -04:00
*/
public function watch(callable $func, $data = null);
2014-09-22 16:47:48 -04:00
}