1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 21:31:18 +01:00
amp/lib/Internal/PrivateObservable.php
Aaron Piotrowski 93ad513ab1 Remove dead code
Deferred and Postponed will never throw from the functions they define.
2016-12-15 17:34:30 -06:00

52 lines
1.2 KiB
PHP

<?php declare(strict_types = 1);
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);
}
}