I see that D has futures, and can create threads but is there anything like "Dart" futures/promises (or I guess javascript if you use a library)?
I want to be able to write code like this -
//
// NOT D code because I can't remember all the syntax!
//
auto fut = myfile.read();
fut.then(function(data) {
// Process data asynchronously when the future completes
};
I want the callback on the same thread as the main code though. This will presumably need some kind of even queue and event dispatching. I think that ASIO in boost provides some similar facilities for C++ but something with a better syntax would be nice.
Is there anything like this in core D, or any simple way to achieve single threaded futures for async code?
I suggest you take a look at vibe.d: http://vibed.org/ It enables you to write performant event driven code like you know from nodejs but in a synchronous manner using D's fibers: http://dlang.org/phobos/core_thread.html#.Fiber