koajs / compose

Middleware composition utility
MIT License
1k stars 147 forks source link

Reworked to catch broken promise chains #148

Open WesleyClements opened 2 years ago

WesleyClements commented 2 years ago

To address the issue outlined in #74 and the original ticket in the koa repo, I've refactored the recursion implementation to make it easier to keep track of whether or not next hasn't resolved. The fundamental thing I've done is to add a proxy for the next middleware that will note when the next dispatch call returns. If any given middleware calls next and resolves before it does we throw an error. Additionally I've stripped out all of the safeguards in production to slim the implementation even more. In production it won't be dissimilar to how things are already implemented. In development though, there will be an increase in memory footprint as, in addition to more variables, there will be an extra stack frame per middleware.

codecov[bot] commented 2 years ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (bff06e9) 100.00% compared to head (a4a8208) 100.00%.

:exclamation: Current head a4a8208 differs from pull request most recent head bd4772c. Consider uploading reports for the commit bd4772c to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #148 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 1 1 Lines 17 33 +16 Branches 5 13 +8 ========================================= + Hits 17 33 +16 ``` | [Impacted Files](https://app.codecov.io/gh/koajs/compose/pull/148?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=koajs) | Coverage Δ | | |---|---|---| | [index.js](https://app.codecov.io/gh/koajs/compose/pull/148?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=koajs#diff-aW5kZXguanM=) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.