Skip to content

Commit

Permalink
stream support queue
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjscc committed Jan 13, 2025
1 parent 2828fa3 commit a9f2da5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Bandwidth.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ public function file(string $path, $p = 0, $length = -1)
public function stream($stream)
{
$_stream = new \React\Stream\ThroughStream();
$stream->on('data', function ($data) use ($_stream) {
$this->concurrent->concurrent(function() use ($_stream, $data){

$concurrent = $this->queue ? $this->concurrent : new Concurrent(1);

$stream->on('data', function ($data) use ($_stream, $concurrent) {
$concurrent->concurrent(function() use ($_stream, $data){
return $this->bucket->removeTokens(1024 * strlen($data))->then(function () use ($_stream, $data) {
$_stream->write($data);
});
});
});

return $_stream;
}

Expand Down

0 comments on commit a9f2da5

Please sign in to comment.