-
Notifications
You must be signed in to change notification settings - Fork 23
Description
The Nim async/await implementation has been successfully used in production for many years now, both in real-world use cases (NimForum, among others) as well as in benchmarks (TechEmpower benchmarks via Jester/HttpBeast). It has also been adapted into the Chronos implementation used by Status for their Ethereum client implementation.
All of these projects have established it as a reliable and easy way to write highly concurrent applications in Nim.
As far as I know, there are three things missing, some more important than others. This RFC aims to document what those are and hopefully drum up some support for their implementation. I strongly believe that the effort needed to implement these is in general low, with the impact being high.
But I would also like to open this RFC to others, if not already covered by the list below, what do you feel is missing? Can we implement a solution within the existing async/await implementation?
Concurrency + Parallelism
A big pain point with Nim's concurrency is that it does not integrate well with Nim's parallelism. I think that a simple fix here would be to make it possible for spawned threads (FlowVars) and channels to be awaitable.
I believe that there isn't a need to head towards the Golang Goroutines which mix concurrency and parallelism. For a systems programming language, having these as separate systems is wise and ultimately gives more control. This is particularly important for something that is in the standard library.
Software such as httpbeast have proven that scaling async/await across threads can be done and that it works well. For other non-server use cases an awaitable threads implementation will be a great stand-in, until we can figure out the disadvantages of this approach (if any).
Future Cancellation
Right now, the only way to cancel a pending operation is to close the FD it is working on. This works in certain circumstances, but is somewhat hacky and not flexible enough. A formal way to cancel futures would be ideal.
Chronos already implements this so it can be used as a source of inspiration for how this should be implemented.
Future Streams
The existing implementation has its issues (just search around the Nim repo for issues relating to future streams) and needs a rework. This is an important component to enable streaming large pieces of data to clients.
A nice practical solution here could be to rely on sendfile.
Useful Resources
- https://tomaka.medium.com/a-look-back-at-asynchronous-rust-d54d63934a1c - cancellation and challenges in the actor model