Skip to content

Commit

Permalink
fix: redablestream should not be locked, when stream transfer (#5790)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name committed May 31, 2024
1 parent c0f19eb commit ad4548d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/spicy-lies-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/server-core': patch
---

fix: redablestream should not be locked, when stream transfer
fix: redablestream 不应该被锁住当 stream 传输时
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,29 @@ export class CacheManager {

return chunk;
});
stream.readable.getReader().closed.then(() => {
const current = Date.now();
const cache: CacheStruct = {
val: html,
cursor: current,
};
this.container.set(key, JSON.stringify(cache), { ttl });
});

body.pipeThrough(stream);
const reader = body.getReader();
const writer = stream.writable.getWriter();

const push = () => {
reader.read().then(({ done, value }) => {
if (done) {
const current = Date.now();
const cache: CacheStruct = {
val: html,
cursor: current,
};
this.container.set(key, JSON.stringify(cache), { ttl });
writer.close();
return;
}

writer.write(value);
push();
});
};

push();

return {
data: stream.readable,
Expand Down

0 comments on commit ad4548d

Please sign in to comment.