emitter = new Emitter; parent::__construct($this->emitter->stream()); } /** * {@inheritdoc} */ public function write(string $data): Promise { return $this->send($data, false); } /** * {@inheritdoc} */ public function end(string $data = ''): Promise { return $this->send($data, true); } /** * @param string $data * @param bool $end * * @return \Amp\Promise */ protected function send(string $data, bool $end = false): Promise { if (!$this->writable) { return new Failure(new StreamException("The stream is not writable")); } if ($end) { $this->writable = false; } $this->emitter->emit($data); return new Success(\strlen($data)); } }