({
onError,
onResult,
resultReturns,
onDone,
doneReturns,
rethrowIfPossible
})
| 281 | } |
| 282 | |
| 283 | callTapsSeries({ |
| 284 | onError, |
| 285 | onResult, |
| 286 | resultReturns, |
| 287 | onDone, |
| 288 | doneReturns, |
| 289 | rethrowIfPossible |
| 290 | }) { |
| 291 | const { taps } = this.options; |
| 292 | const tapsLength = taps.length; |
| 293 | if (tapsLength === 0) return onDone(); |
| 294 | // Inlined findIndex to avoid the callback allocation. |
| 295 | let firstAsync = -1; |
| 296 | for (let i = 0; i < tapsLength; i++) { |
| 297 | if (taps[i].type !== "sync") { |
| 298 | firstAsync = i; |
| 299 | break; |
| 300 | } |
| 301 | } |
| 302 | const somethingReturns = resultReturns || doneReturns; |
| 303 | // doneBreak doesn't depend on the loop variable - hoist to allocate once. |
| 304 | const doneBreak = (skipDone) => { |
| 305 | if (skipDone) return ""; |
| 306 | return onDone(); |
| 307 | }; |
| 308 | let code = ""; |
| 309 | let current = onDone; |
| 310 | let unrollCounter = 0; |
| 311 | for (let j = tapsLength - 1; j >= 0; j--) { |
| 312 | const i = j; |
| 313 | const unroll = |
| 314 | current !== onDone && (taps[i].type !== "sync" || unrollCounter++ > 20); |
| 315 | if (unroll) { |
| 316 | unrollCounter = 0; |
| 317 | code += `function _next${i}() {\n`; |
| 318 | code += current(); |
| 319 | code += "}\n"; |
| 320 | current = () => `${somethingReturns ? "return " : ""}_next${i}();\n`; |
| 321 | } |
| 322 | const done = current; |
| 323 | const content = this.callTap(i, { |
| 324 | onError: (error) => onError(i, error, done, doneBreak), |
| 325 | onResult: |
| 326 | onResult && ((result) => onResult(i, result, done, doneBreak)), |
| 327 | onDone: !onResult && done, |
| 328 | rethrowIfPossible: |
| 329 | rethrowIfPossible && (firstAsync < 0 || i < firstAsync) |
| 330 | }); |
| 331 | current = () => content; |
| 332 | } |
| 333 | code += current(); |
| 334 | return code; |
| 335 | } |
| 336 | |
| 337 | callTapsLooping({ onError, onDone, rethrowIfPossible }) { |
| 338 | if (this.options.taps.length === 0) return onDone(); |
no test coverage detected