(abort, h2stream, body, client, request, socket, contentLength, expectsPayload)
| 1389 | } |
| 1390 | |
| 1391 | async function writeIterable (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) { |
| 1392 | assert(contentLength !== 0 || client[kRunning] === 0, 'iterator body cannot be pipelined') |
| 1393 | |
| 1394 | let callback = null |
| 1395 | function onDrain () { |
| 1396 | if (callback) { |
| 1397 | const cb = callback |
| 1398 | callback = null |
| 1399 | cb() |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | const waitForDrain = () => new Promise((resolve, reject) => { |
| 1404 | assert(callback === null) |
| 1405 | |
| 1406 | if (socket[kError]) { |
| 1407 | reject(socket[kError]) |
| 1408 | } else { |
| 1409 | callback = resolve |
| 1410 | } |
| 1411 | }) |
| 1412 | |
| 1413 | h2stream |
| 1414 | .on('close', onDrain) |
| 1415 | .on('drain', onDrain) |
| 1416 | |
| 1417 | try { |
| 1418 | // It's up to the user to somehow abort the async iterable. |
| 1419 | for await (const chunk of body) { |
| 1420 | if (socket[kError]) { |
| 1421 | throw socket[kError] |
| 1422 | } |
| 1423 | |
| 1424 | const res = h2stream.write(chunk) |
| 1425 | request.onBodySent(chunk) |
| 1426 | if (!res) { |
| 1427 | await waitForDrain() |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | h2stream.end() |
| 1432 | |
| 1433 | request.onRequestSent() |
| 1434 | |
| 1435 | if (!expectsPayload) { |
| 1436 | socket[kReset] = true |
| 1437 | } |
| 1438 | |
| 1439 | client[kResume]() |
| 1440 | } catch (err) { |
| 1441 | abort(err) |
| 1442 | } finally { |
| 1443 | h2stream |
| 1444 | .off('close', onDrain) |
| 1445 | .off('drain', onDrain) |
| 1446 | } |
| 1447 | } |
| 1448 |
no test coverage detected
searching dependent graphs…