Example #1
0
 /**
  * Emits a value from the contained Emitter object.
  *
  * @coroutine
  *
  * @param mixed $value If $value is an instance of \Icicle\Awaitable\Awaitable, the fulfillment value is used
  *     as the value to emit or the rejection reason is thrown from this coroutine. If $value is an instance of
  *     \Generator, it is used to create a coroutine which is then used as an awaitable.
  *
  * @return \Generator
  *
  * @resolve mixed The emitted value (the resolution value of $value)
  *
  * @throws \Icicle\Observable\Exception\CompletedError If the observable has been completed.
  * @throws \Icicle\Observable\Exception\BusyError If the observable is still busy emitting a value.
  * @throws \Icicle\Observable\Exception\DisposedException If no listeners remain on the observable.
  */
 public function emit($value = null) : \Generator
 {
     if (null === $this->emit) {
         $this->emit = (yield $this->started);
     }
     if (!$this->delayed->isPending()) {
         if ($this->delayed->isRejected()) {
             (yield $this->delayed);
             // Throws failure reason.
         }
         throw new CompletedError('The observable was marked as completed.');
     }
     return yield from ($this->emit)($value);
 }