isWritable()) { throw new \LogicException("The destination is not writable"); } if (null !== $bytes) { yield Coroutine::result( yield $destination->write( yield $source->read($bytes) ) ); return; } $written = 0; do { $written += (yield $destination->write( yield $source->read() )); } while ($source->isReadable() && $destination->isWritable()); yield Coroutine::result($written); }