25 ms·
Does C++ yet have something similar to async/await? I have a medium sized JavaScript codebase that uses this (http://github.com/bhouston/behave-graph http://gi
by bhouston 3y ago
Does C++ yet have something similar to async/await?
I have a medium sized JavaScript codebase that uses this (http://github.com/bhouston/behave-graph http://github.com/bhouston/behave-graph) and I could really use a port to C++ so that it can be integrated with the USD project, who has expressed interest.
I couldn't find an equivalent to async/await in my searches so I am fearful that porting this across to C++ is non-trivial.
- __jem 3y agohttps://en.cppreference.com/w/cpp/language/coroutines https://en.cppreference.com/w/cpp/language/coroutines But highly doubt you need anything like async/await for this kind of application. In fact, I'd go as far as to say async/await is almost never needed except for building networked services with truly massive performance demands.
- Kranar 3y agoIf you genuinely have massive performance demands, stay far away from coroutines. For whatever reason the approach C++ took makes them incredibly memory hungry and inefficient.
- jupp0r 3y agoThis is FUD. Watch https://www.youtube.com/watch?v=j9tlJAqMV7U https://www.youtube.com/watch?v=j9tlJAqMV7U.
- lionkor 3y agoYou can look into asio or boost::asio (same thing more or less). These libraries add pretty good async behavior. Of course, you need to know a lot of C++ to understand and use them properly, and they're very verbose. If you need to do things in parallel for performance, you may be better off spinning up a threadpool (like asio's thread_pool) and using a threadsafe queue or similar (i.e. asio's asio::post()) to pass messages and get results. Since you can do it with JS, you likely don't have massive perf requirements, and you just need to write it in simple, synchronous C++ and you may find it to be well fast enough. We also have coroutines, they're async/await. Haven't tried them though.