Skip to content

Commit

Permalink
Allow multiple concurrent buffer calls in Payload
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Jan 1, 2019
1 parent f8ead22 commit d2d5b6a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Payload.php
Expand Up @@ -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;
Expand All @@ -33,6 +39,8 @@ final public function read(?int $length = null): ?string
*/
final public function buffer(): string
{
return buffer($this->source);
$this->buffer = Task::async('Amp\ByteStream\buffer', $this->source);

return Task::await($this->buffer);
}
}

0 comments on commit d2d5b6a

Please sign in to comment.