Skip to content

Instantly share code, notes, and snippets.

View Scooletz's full-sized avatar

Szymon Kulec Scooletz

View GitHub Profile
@clemensv
clemensv / gist:6554605
Last active April 6, 2018 03:16
using Task.WhenAny to drive a pump of multiple async operations in the same context (such as an I/O pump)
/*
Example use (from an email I sent)
I’m using WhenAny to either register for a callback on any of the pending operations and to use
the IO thread that comes up with their respective completion or to execute handling of completed
work on the current thread (‘borrowing’ the IO thread).
So if I read from a socket and from a queue, first both ops hang. Queue read completes and I get
called back on an IO thread which continues the await. I process that completion in the loop.
Meanwhile the socket read completes. That IO thread pops up and just registers the fact that it’s