Dart is single-threaded. Or is it?
There’s a lot to unpack in this three-word sentence. At first glance, it might seem like an easy question with a simple “yes” or “no” answer. However, taking such a simplistic approach will not help us achieve our goal. Answering this question requires that we discuss concepts such as concurrency, synchronicity, threads, parallelism, and blocking. While it may seem overwhelming if you haven’t encountered these concepts before, we will explore them gradually and logically, building our knowledge and experience from the ground up.
Understanding synchronous, concurrent, and parallel operations
There’s nobetter way to understand how the code works than writing, executing, and examining the results. Let’s start by executing the following code:
lib/examples/example1.dart
void main() { print("1"); print("2"); print("3"); ...