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

fix: add start stream on pipe #4132

Merged
merged 2 commits into from
Jul 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
4 changes: 4 additions & 0 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.36.3] - 2024-07-26

- Fix: Support starting the stream on `StreamWrapper.pipe(...)` for shorter syntax when dealing with `node:stream` primitives.

## [0.36.2] - 2024-07-26

- Fix: This release comes with numerous improvements to streaming responses:
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.36.2
0.36.3
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export class Node18UniversalStreamWrapper
}
});

this._startReading();

return dest;
}

Expand Down Expand Up @@ -197,4 +199,28 @@ export class Node18UniversalStreamWrapper
}
}
}

private async _startReading(): Promise<void> {
try {
this._emit("readable");
while (true) {
if (this.paused) {
await new Promise((resolve) => {
this.resumeCallback = resolve;
});
}
const { done, value } = await this.reader.read();
if (done) {
this._emit("end");
this._emit("close");
break;
}
if (value) {
this._emit("data", value);
}
}
} catch (error) {
this._emit("error", error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class UndiciStreamWrapper
}
});

this._startReading();

return dest;
}

Expand Down Expand Up @@ -184,4 +186,28 @@ export class UndiciStreamWrapper
}
}
}

private async _startReading(): Promise<void> {
try {
this._emit("readable");
while (true) {
if (this.paused) {
await new Promise((resolve) => {
this.resumeCallback = resolve;
});
}
const { done, value } = await this.reader.read();
if (done) {
this._emit("end");
this._emit("close");
break;
}
if (value) {
this._emit("data", value);
}
}
} catch (error) {
this._emit("error", error);
}
}
}
2 changes: 0 additions & 2 deletions scripts/browser-startup-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ echo "DISABLE_ESLINT_PLUGIN=true" >> .env

npm install
output=$(timeout 25s npm run start &)
sleep 30
echo "$output"
if echo "$output" | grep -q "Compiled successfully!"; then
echo "Compiled successfully"
Expand All @@ -55,5 +54,4 @@ else
exit 1
fi
cd ../../..
pwd
rm -rf browser-test
3 changes: 1 addition & 2 deletions scripts/cloudflare-startup-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export default {
return new Response("Hello World!");
},
};' > src/index.ts
output=$(timeout 1s wrangler dev &)
sleep 1
output=$(timeout 5s wrangler dev &)
echo "$output"
if echo "$output" | grep -q "SeedApiClient import was successful"; then
echo "Compiled successfully"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading