1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-26 11:54:54 +01:00

Allow multiple concurrent buffer calls in Payload

This commit is contained in:
Niklas Keller 2019-01-01 13:29:47 +01:00
parent f8ead22238
commit d2d5b6a7db

View File

@ -2,12 +2,18 @@
namespace Amp\ByteStream;
use Concurrent\Awaitable;
use Concurrent\Stream\ReadableStream;
use Concurrent\Task;
class Payload implements ReadableStream
{
/** @var ReadableStream */
private $source;
/** @var Awaitable */
private $buffer;
public function __construct(ReadableStream $source)
{
$this->source = $source;
@ -33,6 +39,8 @@ class Payload implements ReadableStream
*/
final public function buffer(): string
{
return buffer($this->source);
$this->buffer = Task::async('Amp\ByteStream\buffer', $this->source);
return Task::await($this->buffer);
}
}