-
Notifications
You must be signed in to change notification settings - Fork 82
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
[API breaking] Add types to inbound/outbound debug handlers #81
base: main
Are you sure you want to change the base?
Conversation
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
@swift-server-bot test this please |
Yeah, it should’ve been |
@swift-nio-bot add to whitelist |
@swift-server-bot test this please |
@weissi as a short-term win, what do you think of implementing a similar but typed |
Are we explicitly opposed to having a public |
Yes. It’s deliberately opaque and allowing manual unwrapping doesn’t really enable anything that you couldn’t achieve today. Set your InboundIn to Any, then you have self.unwrapInboundIn to Any and from there to anywhere |
IMO something doesn't feel quite right about using |
@Davidde94 this handler doesn’t have type information so typing it is impossible (without changing its type). It was designed to handle |
Updated this PR to target |
Add generic types to inbound and outbound debug handlers. The current implementation is API-breaking, however it's entirely possible to implement in a "minor-version" way (detail below).
Motivation:
I've found that the provided debug handlers are not massively useful without types, as it's not possible (as far as I'm aware) to unwrap the data inside NIOAny outside of a channel handler. This means that to debug-print data inside my application I have to essentially recreate the logic provided by the print handlers. This seems redundant, and it would be nice to have an "official" implementation.
Modifications:
Add generic types
T
to bothInbound
andDebugOutboundEventsHandler
. Inside the read event, instead of passing down aNIOAny
, pass the unwrapped data.Result:
[After your change, what will change.]
Notes:
This is an API-breaking change. It's also possible to create new classes, e.g.
TypedDebugInboundEventsHandler
, etc. Alternatively we could cleverly expose something from NIOAny to allow unwrapping outside of aChannelHandler
. E.g.nioAny.unwrap(as: T)
.