OutputStream Delegate issue

Currently I'm using swift 5.3.1 MacOS / 5.3.2 Linux and on either platform an OutputStream delegate does not get fired on a stream event - simple reproducer below - I expected the delegate would be called at least on openCompleted and hasBytesAvailable any pointers on what I'm doing wrong would be appreciated.

The Stream API is run loop based [1] and you don’t seem to be running the run loop. If you insert this line:

RunLoop.current.run(until: Date(timeIntervalSinceNow: 1.0))

between lines 19 and 20, you’ll see FOO get printed twice.

This is, however, just a proof of concept hack. The correct approach here very much depends on the context. If you can supply more details, we can advise you further.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

[1] Assuming you’re using it asynchronously, which you are in this example.

Thanks for that, to add context in regard to the actual use case its a cli app which passes XML off to a library which uses GCD for processing - during the processing the library dumps XML to the OutputStream - the end intention in this case was to use the delegate to dump data to stdout - the library itself is intended to sit behind tcp/http/ - I had been looking into swift NIO also but have stuck with foundation to get things going. I have used GCD extensively in the past in the objc realm but still getting my head around RunLoop vs Dispatch in swift.

@eskimo Read up the apple/swift doc's further around the RunLoop and all sorted now - thanks for your time.

Terms of Service

Privacy Policy

Cookie Policy