Well, . Dart has a , of execution. However, commonly you’ll see a code using have a comment something to the effect of . What does that mean? no single thread, or event-loop Future “// Avoid race conditions: Check for …” Read on the Dart site. New to futures? asynchronous programming: Futures While has a single thread of execution, it can interact with other code (Dart or otherwise, such as server-side) that runs in a separate thread. What as an API means is simply “ ”. That time? It could be at the end of the microtask loop, it could be after a second, after a file is read from disk, after an RPC completes. It could also be never (due to a timeout, for example). Dart Future<T> get a value, T, at a future point in time You can review . all of the examples in this blog post on GitHub Let’s introduce a simple example: We print the string “1”, “2”, “3”, and “4” — seemingly in order, but in reality it will print “1”, “4”, “2”, and “3”. That’s because “1” is printed , while “2” is printed at the end of the , and “3” is printed a future synchronously microtask loop event loop. You can also use the API to adapt a non- API: Completer Future But, what about ? Isolates Dart is able to spawn standalone processes, called (web workers in dart2js), which do not share memory when the main program, but are able to asynchronously, in another process (effectively a thread of sorts) is able to do computations without blocking the main thread. Isolates In the below example we compute the fibonacci sequence twice — once synchronously in the same thread — and once asynchronously in another isolate. In this example, is still used — it just means “will execute in the future”, remember? In this case, we spawn another isolate, ask it to compute, and the future completes when we have a result. If, for example, your computer was under heavy load it could take a little while. Future Seem confusing? The API is fairly low-level. When using in your own code I’d recommend looking at or the . isolate package:isolate class from package:stream_channel IsolateChannel How about another example, this time file I/O. We can the difference between and ourselves using an Isolate: simulate File#readAsStringSync File#readAsString In this case we read three times — once synchronously, once asynchronously (i.e. in another thread managed by the Dart VM), and finally once more synchronously, but in another isolate. “file.json” Since Dart 1.22.0, we’ve introduced a limited union type, — which represents either or It’s valid in the type system to have either. As an example, take a look at caching the result of a future: FutureOr<T> Future<T> T. I hope you enjoyed this short blog post, and if you have any questions about using futures or the API in Dart leave a comment here or on twitter. Thanks! asynchronous is how hackers start their afternoons. We’re a part of the family. We are now and happy to opportunities. Hacker Noon @AMI accepting submissions discuss advertising & sponsorship To learn more, , , or simply, read our about page like/message us on Facebook tweet/DM @HackerNoon. If you enjoyed this story, we recommend reading our and . Until next time, don’t take the realities of the world for granted! latest tech stories trending tech stories