diff --git a/docs/migration-guide-NIO1-to-NIO2.md b/docs/migration-guide-NIO1-to-NIO2.md index c4781276..5e1cbfda 100644 --- a/docs/migration-guide-NIO1-to-NIO2.md +++ b/docs/migration-guide-NIO1-to-NIO2.md @@ -62,3 +62,11 @@ NIO 2 only supports Swift 5 so after the migration you should change the first l ## Step 6: Watch out for more subtle changes - Make sure you close your `Channel` if there's an unhandled error. Usually, the right thing to do is to invoke `context.close(promise: nil)` when `errorCaught` is invoked on your last `ChannelHandler`. Of course, handle all the errors you know you can handle but `close` on all others. This has always been true for NIO 1 too but in NIO 2 we have removed some of the automatic `Channel` closes in the `HTTPDecoder`s and `ByteToMessageDecoder`s have been removed. Why have they been removed? So a user can opt out of the automatic closure. +- If you have a `ByteToMessageDecoder` or a `MessageToByteEncoder`, you will now need to wrap them before adding them to the pipeline. For example: + +```swift + channel.pipeline.addHandler(ByteToMessageHandler(MyExampleDecoder())).flatMap { + channel.pipeline.addHandler(MessageToByteHandler(MyExampleEncoder())) + } +``` +- Apart from this, most `ByteToMessageDecoder`s should continue to work. There is however one more subtle change: In SwiftNIO 1, you could (illegally) intercept arbitrary `ChannelInboundHandler` or `ChannelOutboundHandler` events in `ByteToMessageHandler`s. This did never work correctly (because the `ByteToMessageDecoder` driver would then not receive those events anymore). In SwiftNIO 2 this is fixed and you won't receive any of the standard `ChannelHandler` events in `ByteToMessageDecoder`s anymore. \ No newline at end of file