mirror of
https://github.com/apple/swift-nio
synced 2026-11-27 05:04:22 +00:00
* Add `withInboundOutboud` to `NIOAsyncChannel` and deprecate deinit based cleanup # Motivation We just released our new async NIO APIs and have already gotten quite a bunch of feedback from adopters. One of the feedback was that the deinit based closing that we have added to the `NIOAsyncChannel` has caused problems since it leads to unexpected closure of their `Channel`. Furthermore, it makes it impossible to determine how many open sockets a program has at any given time since deinit based clean up relies on the optimizer and can happen at random times. # Modifications This PR adds new inits to `NIOAsyncSequenceProducer` and `NIOAsyncWriter` which disable the `deinit` based clean up and instead replace them with an assertion. This allows developers to still catch these issues at debug time. Furthermore, I added a new `withInboundOutbound` scoped access to `NIOAsyncChannel` which will close the channel at the end of the scope. This still gives users a nice API while not having to care much about closing themselves. # Result We are no longer using deinit based clean up and bring back one of the core principles of NIO which is deterministic resource usage. * Review comments * Internal labels for closure arguments * Rename to `executeThenCloseChannel` * Actually call `sinkDeinitialized` * Change preconditions * Move logic to deinits * Rename to `executeThenClose` and review nits