5 ms·
async/await is HUGE. It opens an almost frictionless asynchronous pathway from your code all the way down to asynchronous capabilities of the underlying platfo
by useerup 12y ago
async/await is HUGE.
It opens an almost frictionless asynchronous pathway from your code all the way down to asynchronous capabilities of the underlying platform. Which was always the problem with leveraging async/overlapped IO: It was too complex and it turned your application logic inside-out because everything had to be performed in callbacks. async/await takes that on directly: You get everything executed in callbacks - only the callbacks are transparently created for you along with the necessary finite state machines so that your code still composes with exceptions, loops, branches working the way you expect - even across those "invisible" callbacks.
For server scalability as well as responsiveness on small devices (keeping number of thread low - even at one - while still serving the UI), that is really an advantage.
There is no "fakes" on the way - no extra threads being started just to wait for completion of an otherwise synchronous API. If the platform supports asynchronous IO/network/disk/database you can leverage that without any of the strange complexities of other languages.
Worth mentioning here is that Windows has an easier scalable and better designed completion oriented async model compared to the readiness oriented model of Linux - which is mostly limited to sockets anyway.
OS X has GCD - which is also a completion oriented model. I look forward to seeing how .NET with real global optimizing compilers from MS will do on OS X versus Linux versos Windows (on a Mac, obviously).
- Rapzid 12y agoTasks are pretty awesome and just about as convenient as Go-routines. Now if we could just get typed channels in .Net >:]
- tracker1 12y agoI don't think it would be very hard at all to create a generic CSP system with C# (or F# for that matter). I've built similar systems using WCF.
- Paradigma11 12y agoDoesn't rx fill that role?
- Matthias247 12y agoWith Rx you can do similar things but the semantics are different. When you use an Rx Stream you will get the data pushed from a different thread. With Go-like channels you pull the data from the other thread (or the channel).
- Matthias247 12y agoHow about BlockingCollection<T>? If I understand it correctly you can even have select like sementics with BlockingCollection.TakeFromAny(...) Edit: Sorry, messed it up a little bit. BlockingCollection will block your current thread for any other computation and does not allow to await on it. But there seem to be alternatives: http://stackoverflow.com/questions/21225361/is-there-anything-like-asynchronous-blockingcollectiont http://stackoverflow.com/questions/21225361/is-there-anythin... http://blog.stephencleary.com/2012/12/async-producer-consumer-queue-3-more.html http://blog.stephencleary.com/2012/12/async-producer-consume...
- vishnugupta 12y agoCould you please contrast async/await implementation with Future in Java? From the usability standpoint I see that they are more or less similar. However since you state that async/await exploits the asynchronous capabilities of the underlying platform I'm really curious to know how is this different from the way the way Future is implemented in a JVM.
- pjmlp 12y agoFutures in .NET are tasks and the Fork/Join framework is TPL (Task Parallel Library). Async/await allows developers to write code that looks sequential, but is rewritten by the compiler into a sequence of coroutines built on top of TPL, while taking care error propagation happens correctly.
- emcrazyone 12y agoI'm a C# newbie but a long time C++ guy. I've done tons of work with Overlapped IO under Windows and similar stuff with Linux using epoll type signaling to threads. I've completely wrapped much of this using C++ Signals & Slots library making callbacks as simple as adding a Signal<> to my object and a Slot anywhere I wanted to pick up said signal. I'm intrigued by how C# makes this situation better than the way I've been dealing with it with my amped up C++ delegates (aka signal & slots). Could you recommend any C# for C++ developer type links for getting acquainted ?
- recursive 12y agoFYI emcrazyone, it appears that you have been shadow-banned. I don't have any specific recommendations for your question, but I thought you should know.
- Cthulhu_ 12y agoTelling people they have been shadow-banned defeats the purpose of it.
- jabbernotty 12y agoIt does not serve a purpose to me. To whom does it serve a purpose to shadow-ban that user, and what purpose is it?
- recursive 12y agoIn that case, it's a purpose that I don't support.
- orf 12y agoFYI Python has had an await equivalent for a looong time through the Twisted networking library and now asyncio. It has the same semantics, but you use the yield keyword instead of await. Also as of recently there is a standard library event loop package, and as far as I know Twisted was the defacto event loop on 2.x for most types of work.
- pjmlp 12y agoHaving used Python during my time at CERN, I would never use it for anything besides scripting tasks. Maybe when PyPy reaches feature parity with mainline Python.