mirror of
https://github.com/danog/amp.git
synced 2024-12-04 18:38:17 +01:00
55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Amp\Internal;
|
|
|
|
use Amp\Observable;
|
|
|
|
/**
|
|
* An observable that cannot externally emit values. Used by Postponed in development mode.
|
|
*/
|
|
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\Awaitable
|
|
*/
|
|
$emit = function ($value = null) {
|
|
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 \Exception $reason
|
|
*/
|
|
$fail = function ($reason) {
|
|
$this->fail($reason);
|
|
};
|
|
|
|
try {
|
|
$emitter($emit, $resolve, $fail);
|
|
} catch (\Throwable $exception) {
|
|
$this->fail($exception);
|
|
} catch (\Exception $exception) {
|
|
$this->fail($exception);
|
|
}
|
|
}
|
|
}
|