| 63 | // so one bad request doesn't abort the wave — they're reported in the |
| 64 | // final verdict instead. |
| 65 | const pool = async (thunks, width = 4) => { |
| 66 | const failures = []; |
| 67 | const queue = [...thunks]; |
| 68 | await Promise.all( |
| 69 | Array.from({ length: width }, async () => { |
| 70 | while (queue.length) { |
| 71 | const thunk = queue.shift(); |
| 72 | try { |
| 73 | await thunk(); |
| 74 | } catch (err) { |
| 75 | failures.push(String(err)); |
| 76 | } |
| 77 | } |
| 78 | }), |
| 79 | ); |
| 80 | return failures; |
| 81 | }; |
| 82 | |
| 83 | const drain = async (res, expectedStatuses = [200]) => { |
| 84 | // Consume the body so sockets/streams actually complete |