mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
feat(core): add Deno.core.writeAll(rid, chunk) (#16228)
This commit adds a new op_write_all to core that allows writing an entire chunk in a single async op call. Internally this calls `Resource::write_all`. The `writableStreamForRid` has been moved to `06_streams.js` now, and uses this new op. Various other code paths now also use this new op. Closes #16227
This commit is contained in:
parent
4d6aed1b52
commit
1ab3691b09
10 changed files with 85 additions and 43 deletions
|
@ -4,7 +4,8 @@
|
|||
((window) => {
|
||||
const core = window.Deno.core;
|
||||
const { BadResourcePrototype, InterruptedPrototype, ops } = core;
|
||||
const { WritableStream, readableStreamForRid } = window.__bootstrap.streams;
|
||||
const { readableStreamForRid, writableStreamForRid } =
|
||||
window.__bootstrap.streams;
|
||||
const {
|
||||
Error,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
|
@ -65,39 +66,6 @@
|
|||
return core.opAsync("op_dns_resolve", { query, recordType, options });
|
||||
}
|
||||
|
||||
function tryClose(rid) {
|
||||
try {
|
||||
core.close(rid);
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
function writableStreamForRid(rid) {
|
||||
return new WritableStream({
|
||||
async write(chunk, controller) {
|
||||
try {
|
||||
let nwritten = 0;
|
||||
while (nwritten < chunk.length) {
|
||||
nwritten += await write(
|
||||
rid,
|
||||
TypedArrayPrototypeSubarray(chunk, nwritten),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
controller.error(e);
|
||||
tryClose(rid);
|
||||
}
|
||||
},
|
||||
close() {
|
||||
tryClose(rid);
|
||||
},
|
||||
abort() {
|
||||
tryClose(rid);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
class Conn {
|
||||
#rid = 0;
|
||||
#remoteAddr = null;
|
||||
|
@ -353,7 +321,4 @@
|
|||
Datagram,
|
||||
resolveDns,
|
||||
};
|
||||
window.__bootstrap.streamUtils = {
|
||||
writableStreamForRid,
|
||||
};
|
||||
})(this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue