It's a little bit unclear to be how to use initWithUpgradeForSession safely.
Imagine we have a class like this:
@implementation PPNUDPSessionPipeWrapper {
NWUDPSession *_session;
NWUDPSession *_upgradedSession;
}
- (void) startReadingPackets() {
[_session
setReadHandler:^(NSArray<NSData *> *datagrams,
NSError *error) {
// process datagrams
[_session writeMultipleDatagrams:datagrams
completionHandler:^(NSError *error) {
// Handle error
}];
}];
-(void)didHaveBetterPath {
_upgradedSession =
[[NWUDPSession alloc]
initWithUpgradeForSession:_session];
[self waitForSessionToBeReady: _upgradedSession];
// How can I swap `_session` with the
// `_upgradedSession` safely? Will iOS guarantee the
// readHandler on `_session` will not be called any
// more?
}