1
0
mirror of https://github.com/danog/byte-stream.git synced 2025-01-22 13:51:18 +01:00

Awaitable → Promise

This commit is contained in:
Aaron Piotrowski 2016-11-14 15:05:19 -06:00
parent 6990d8675e
commit 32df68151a
3 changed files with 17 additions and 17 deletions

View File

@ -3,7 +3,7 @@
namespace Amp\Stream; namespace Amp\Stream;
use Amp\{ Deferred, Failure, Success }; use Amp\{ Deferred, Failure, Success };
use Interop\Async\Awaitable; use Interop\Async\Promise;
/** /**
* Serves as buffer that implements the stream interface, allowing consumers to be notified when data is available in * Serves as buffer that implements the stream interface, allowing consumers to be notified when data is available in
@ -65,7 +65,7 @@ class MemoryStream implements Stream {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function read(int $bytes = null, string $delimiter = null): Awaitable { public function read(int $bytes = null, string $delimiter = null): Promise {
if ($bytes !== null && $bytes <= 0) { if ($bytes !== null && $bytes <= 0) {
throw new \InvalidArgumentException("The number of bytes to read should be a positive integer or null"); throw new \InvalidArgumentException("The number of bytes to read should be a positive integer or null");
} }
@ -78,7 +78,7 @@ class MemoryStream implements Stream {
$this->reads->push([$bytes, $delimiter, $deferred]); $this->reads->push([$bytes, $delimiter, $deferred]);
$this->checkPendingReads(); $this->checkPendingReads();
return $deferred->getAwaitable(); return $deferred->promise();
} }
/** /**
@ -124,14 +124,14 @@ class MemoryStream implements Stream {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function write(string $data): Awaitable { public function write(string $data): Promise {
return $this->send($data, false); return $this->send($data, false);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function end(string $data = ''): Awaitable { public function end(string $data = ''): Promise {
return $this->send($data, true); return $this->send($data, true);
} }
@ -139,9 +139,9 @@ class MemoryStream implements Stream {
* @param string $data * @param string $data
* @param bool $end * @param bool $end
* *
* @return \Interop\Async\Awaitable * @return \Interop\Async\Promise
*/ */
protected function send(string $data, bool $end = false): Awaitable { protected function send(string $data, bool $end = false): Promise {
if (!$this->writable) { if (!$this->writable) {
return new Failure(new \LogicException("The stream is not writable")); return new Failure(new \LogicException("The stream is not writable"));
} }

View File

@ -2,7 +2,7 @@
namespace Amp\Stream; namespace Amp\Stream;
use Interop\Async\Awaitable; use Interop\Async\Promise;
interface Stream { interface Stream {
/** /**
@ -23,23 +23,23 @@ interface Stream {
* @param int|null $bytes * @param int|null $bytes
* @param string|null $delimiter * @param string|null $delimiter
* *
* @return \Interop\Async\Awaitable<string> Resolves with bytes read from the stream. * @return \Interop\Async\Promise<string> Resolves with bytes read from the stream.
*/ */
public function read(int $bytes = null, string $delimiter = null): Awaitable; public function read(int $bytes = null, string $delimiter = null): Promise;
/** /**
* @param string $data * @param string $data
* *
* @return \Interop\Async\Awaitable<int> * @return \Interop\Async\Promise<int>
*/ */
public function write(string $data): Awaitable; public function write(string $data): Promise;
/** /**
* @param string $data * @param string $data
* *
* @return \Interop\Async\Awaitable<int> * @return \Interop\Async\Promise<int>
*/ */
public function end(string $data = ''): Awaitable; public function end(string $data = ''): Promise;
/** /**
* Closes the stream and fails any pending reads or writes. * Closes the stream and fails any pending reads or writes.

View File

@ -3,7 +3,7 @@
namespace Amp\Stream; namespace Amp\Stream;
use Amp\Coroutine; use Amp\Coroutine;
use Interop\Async\Awaitable; use Interop\Async\Promise;
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
if (\strlen('…') !== 3) { if (\strlen('…') !== 3) {
@ -17,9 +17,9 @@ if (\strlen('…') !== 3) {
* @param \Amp\Stream\Stream $destination * @param \Amp\Stream\Stream $destination
* @param int|null $bytes * @param int|null $bytes
* *
* @return \Interop\Async\Awaitable * @return \Interop\Async\Promise
*/ */
function pipe(Stream $source, Stream $destination, int $bytes = null): Awaitable { function pipe(Stream $source, Stream $destination, int $bytes = null): Promise {
return new Coroutine(__doPipe($source, $destination, $bytes)); return new Coroutine(__doPipe($source, $destination, $bytes));
} }