Skip to content

Commit

Permalink
Support for streamed output #22
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Mar 22, 2022
1 parent 2247e37 commit 97399e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ext-json": "*",
"ext-sockets": "*",
"psr/log": "^1.0|^2.0|^3.0",
"spiral/goridge": "^3.0",
"spiral/goridge": "^3.2.0",
"symfony/polyfill-php80": "^1.23",
"composer-runtime-api": "^2.0"
},
Expand All @@ -37,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
"dev-master": "2.3.x-dev"
}
},
"suggest": {
Expand Down
12 changes: 8 additions & 4 deletions src/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ final class Payload
* Execution context (binary).
*
* @psalm-readonly
* @var string
*/
public string $header = '';

/**
* @param string|null $body
* @param string|null $header
* End of stream.
* The {@see true} value means the Payload block is last in the stream.
*
* @psalm-readonly
*/
public function __construct(?string $body, ?string $header = null)
public bool $eos = true;

public function __construct(?string $body, ?string $header = null, bool $eos = true)
{
$this->body = $body ?? '';
$this->header = $header ?? '';
$this->eos = $eos;
}
}
11 changes: 7 additions & 4 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function waitPayload(): ?Payload
*/
public function respond(Payload $payload): void
{
$this->send($payload->body, $payload->header);
$this->send($payload->body, $payload->header, $payload->eos);
}

/**
Expand All @@ -123,13 +123,16 @@ public function stop(): void
}

/**
* @param string $body
* @param string $header
* @param bool $eos End of stream
*/
private function send(string $body = '', string $header = ''): void
private function send(string $body = '', string $header = '', bool $eos = true): void
{
$frame = new Frame($header . $body, [\strlen($header)]);

if (!$eos) {
$frame->byte10 = Frame::BYTE10_STREAM;
}

$this->sendFrame($frame);
}

Expand Down

0 comments on commit 97399e1

Please sign in to comment.