3 ms·
One thing I really like about async/await is that it hooks into existing .NET infrastructure for issuing calls on other threads. As a result, you can implement
by kevingadd 10y ago
One thing I really like about async/await is that it hooks into existing .NET infrastructure for issuing calls on other threads. As a result, you can implement your own synchronization context and control how the async callbacks run and what thread they run on - if you have your own job scheduler, you can run them inside that. Technically this means you can use async/await for single-threaded workloads, by running all the callbacks yourself on the main thread.
Writing your own synchronization context for these purposes is incredibly easy, as well:
https://github.com/sq/Fracture/blob/ed408e0a84afb0c68d7e81bec5f2dde0b869b413/Squared/TaskLib/TaskScheduler.cs#L153 https://github.com/sq/Fracture/blob/ed408e0a84afb0c68d7e81be...