public function write($socket, $dataToWrite) { $this->promisor = new Deferred(); $this->socket = $socket; $this->buffer = $dataToWrite; \Amp\immediately(function () { $this->doWrite(); }); return $this->promisor->promise(); }