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:
parent
6990d8675e
commit
32df68151a
@ -3,7 +3,7 @@
|
||||
namespace Amp\Stream;
|
||||
|
||||
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
|
||||
@ -65,7 +65,7 @@ class MemoryStream implements Stream {
|
||||
/**
|
||||
* {@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) {
|
||||
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->checkPendingReads();
|
||||
|
||||
return $deferred->getAwaitable();
|
||||
return $deferred->promise();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,14 +124,14 @@ class MemoryStream implements Stream {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write(string $data): Awaitable {
|
||||
public function write(string $data): Promise {
|
||||
return $this->send($data, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function end(string $data = ''): Awaitable {
|
||||
public function end(string $data = ''): Promise {
|
||||
return $this->send($data, true);
|
||||
}
|
||||
|
||||
@ -139,9 +139,9 @@ class MemoryStream implements Stream {
|
||||
* @param string $data
|
||||
* @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) {
|
||||
return new Failure(new \LogicException("The stream is not writable"));
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Amp\Stream;
|
||||
|
||||
use Interop\Async\Awaitable;
|
||||
use Interop\Async\Promise;
|
||||
|
||||
interface Stream {
|
||||
/**
|
||||
@ -23,23 +23,23 @@ interface Stream {
|
||||
* @param int|null $bytes
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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.
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace Amp\Stream;
|
||||
|
||||
use Amp\Coroutine;
|
||||
use Interop\Async\Awaitable;
|
||||
use Interop\Async\Promise;
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (\strlen('…') !== 3) {
|
||||
@ -17,9 +17,9 @@ if (\strlen('…') !== 3) {
|
||||
* @param \Amp\Stream\Stream $destination
|
||||
* @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));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user