1
0
mirror of https://github.com/danog/amp.git synced 2024-12-04 02:17:54 +01:00
amp/lib/Internal/PrivateObservable.php
Aaron Piotrowski 5651240615 Update to promise spec v0.3
Dropped strict-types due to spec requiring weak types in callbacks.
2016-12-29 16:29:27 -06:00

52 lines
1.2 KiB
PHP

<?php
namespace Amp\Internal;
use Amp\Observable;
use Interop\Async\Promise;
/**
* An observable that cannot externally emit values. Used by Postponed in development mode.
*
* @internal
*/
final class PrivateObservable implements Observable {
use Producer;
/**
* @param callable(callable $emit, callable $complete, callable $fail): void $emitter
*/
public function __construct(callable $emitter) {
/**
* Emits a value from the observable.
*
* @param mixed $value
*
* @return \Interop\Async\Promise
*/
$emit = function ($value = null): Promise {
return $this->emit($value);
};
/**
* Completes the observable with the given value.
*
* @param mixed $value
*/
$resolve = function ($value = null) {
$this->resolve($value);
};
/**
* Fails the observable with the given exception.
*
* @param \Throwable $reason
*/
$fail = function (\Throwable $reason) {
$this->fail($reason);
};
$emitter($emit, $resolve, $fail);
}
}