Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify laziness of frames sequence #6

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [Unreleased]

### Changed

- Requires `innmind/immutable:~5.7`
- The `Sequence` of frames to publish a message is only lazy when the message content is a lazy sequence of chunks

## 5.0.0 - 2024-03-10

### Changed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"require": {
"php": "~8.2",
"innmind/immutable": "~5.2",
"innmind/immutable": "~5.7",
"innmind/time-continuum": "~3.1",
"innmind/math": "~6.0",
"innmind/url": "~4.1",
Expand Down
47 changes: 21 additions & 26 deletions src/Transport/Protocol/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,28 @@ public function publish(
Publish $command,
MaxFrameSize $maxFrameSize,
): Sequence {
// we use a lazy sequence to allow streaming frames for messages having
// a lazy sequence of chunks for a body
$frames = Sequence::lazyStartingWith(
Frame::method(
$channel,
Method::basicPublish,
UnsignedShortInteger::internal(0), // ticket (reserved)
ShortString::of(Str::of($command->exchange())),
ShortString::of(Str::of($command->routingKey())),
Bits::of(
$command->mandatory(),
$command->immediate(),
return $maxFrameSize
->chunk($command->message())
->map(static fn($chunk) => Frame::body($channel, $chunk))
->prepend(Sequence::of(
Frame::method(
$channel,
Method::basicPublish,
UnsignedShortInteger::internal(0), // ticket (reserved)
ShortString::of(Str::of($command->exchange())),
ShortString::of(Str::of($command->routingKey())),
Bits::of(
$command->mandatory(),
$command->immediate(),
),
),
),
Frame::header(
$channel,
MethodClass::basic,
UnsignedLongLongInteger::of($command->message()->length()),
...$this->serializeProperties($command->message()),
),
);

return $frames->append(
$maxFrameSize
->chunk($command->message())
->map(static fn($chunk) => Frame::body($channel, $chunk)),
);
Frame::header(
$channel,
MethodClass::basic,
UnsignedLongLongInteger::of($command->message()->length()),
...$this->serializeProperties($command->message()),
),
));
}

/**
Expand Down
Loading