| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fbed90b commit f0ee316
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ const { | |||
| 13 | 13 | ArrayPrototypePush, | |
| 14 | 14 | ArrayPrototypeSlice, | |
| 15 | 15 | PromisePrototypeThen, | |
| 16 | + PromiseResolve, | ||
| 16 | 17 | SymbolAsyncIterator, | |
| 17 | 18 | SymbolIterator, | |
| 18 | 19 | TypedArrayPrototypeGetByteLength, | |
@@ -922,7 +923,14 @@ async function pipeTo(source, ...args) { | |||
| 922 | 923 | return waitForSyncBackpressure(); | |
| 923 | 924 | } | |
| 924 | 925 | const opts = signal ? { __proto__: null, signal } : undefined; | |
| 925 | - return PromisePrototypeThen(writer.writev(batch, opts), () => { | ||
| 926 | + const result = writer.writev(batch, opts); | ||
| 927 | + if (result === undefined) { | ||
| 928 | + for (let i = 0; i < batch.length; i++) { | ||
| 929 | + totalBytes += TypedArrayPrototypeGetByteLength(batch[i]); | ||
| 930 | + } | ||
| 931 | + return; | ||
| 932 | + } | ||
| 933 | + return PromisePrototypeThen(PromiseResolve(result), () => { | ||
| 926 | 934 | for (let i = 0; i < batch.length; i++) { | |
| 927 | 935 | totalBytes += TypedArrayPrototypeGetByteLength(batch[i]); | |
| 928 | 936 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,26 @@ async function testWritevAsyncFallback() { | |||
| 46 | 46 | assert.ok(batches.some((b) => b.length > 1)); | |
| 47 | 47 | } | |
| 48 | 48 | ||
| 49 | + // Multi-chunk batch with synchronous writev success (returns undefined) | ||
| 50 | + async function testWritevSyncUndefinedSuccess() { | ||
| 51 | + const chunks = []; | ||
| 52 | + const writer = { | ||
| 53 | + write(chunk) { | ||
| 54 | + chunks.push(chunk); | ||
| 55 | + }, | ||
| 56 | + writev(batch) { | ||
| 57 | + chunks.push(...batch); | ||
| 58 | + }, | ||
| 59 | + end() {}, | ||
| 60 | + }; | ||
| 61 | + async function* source() { | ||
| 62 | + yield [new Uint8Array([65]), new Uint8Array([66])]; | ||
| 63 | + } | ||
| 64 | + const total = await pipeTo(source(), writer); | ||
| 65 | + assert.strictEqual(total, 2); | ||
| 66 | + assert.strictEqual(Buffer.concat(chunks).toString(), 'AB'); | ||
| 67 | + } | ||
| 68 | + | ||
| 49 | 69 | // writevSync returns false — falls through to async writev | |
| 50 | 70 | async function testWritevSyncFails() { | |
| 51 | 71 | const asyncCalls = []; | |
@@ -190,6 +210,7 @@ async function testPipeToSyncWriteFallback() { | |||
| 190 | 210 | Promise.all([ | |
| 191 | 211 | testWritevSyncSuccess(), | |
| 192 | 212 | testWritevAsyncFallback(), | |
| 213 | + testWritevSyncUndefinedSuccess(), | ||
| 193 | 214 | testWritevSyncFails(), | |
| 194 | 215 | testWriteSyncFailsMidBatch(), | |
| 195 | 216 | testWriteSyncAlwaysFails(), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments