-
Notifications
You must be signed in to change notification settings - Fork 544
fix: handle terminal middleware without mutating chains #3534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
871939d
fca0203
28e2e95
0a21f94
a7dab76
df22183
4d4155f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,12 @@ export interface StreamHandler { | |
|
|
||
| /** | ||
| * Stream middleware allows accessing stream data outside of the stream handler | ||
| * | ||
| * Return false to stop the middleware chain without aborting the stream. | ||
| * Throw or reject to abort the stream. | ||
| */ | ||
| export interface StreamMiddleware { | ||
| (stream: Stream, connection: Connection, next: (stream: Stream, connection: Connection) => void): void | Promise<void> | ||
| (stream: Stream, connection: Connection, next: (stream: Stream, connection: Connection) => void): void | false | Promise<void | false> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be false - kind of want false to be an explicit option to cancel the middleware... or could make it true & void do the same thing which feels a bit off
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thinking about cases where the function returns some boolean logic. would have to coerce to void or false to stop or not stop the middleware while also fitting the type constraint.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The semantics get a bit awkward because you need to choose what the boolean means - e.g. |
||
| } | ||
|
|
||
| export interface StreamHandlerOptions extends AbortOptions { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could said returning true or void lets the middleware continue.