DISCOVER FLUTTER — WEEK #16
Asynchronous Dart: Isolates and Event Loops
Core facts about Isolates and Event Loops
Reading articles on this topic, I came up with the idea to single out only the core facts concerning Isolates and the Event loop as the basis of asynchronous programming in Dart.
First and foremost Dart is single thread. When we say single thread we mean the fact that Dart executes one operation at a time, so it cannot be interrupted by any other Dart code.
Isolates
When you start your Flutter app, a new thread process is created and launched. In Dart language, this thread process is called Isolate.
I would single out the next core facts about Dart Isolates:
- Isolates = Thread process
- 1 Isolate has 1 Event Loop and 2 Queues (MicroTask and Event)— Each Isolate has its own “Event Loop” — code that runs inside an Isolate will run independently of another Isolate. So Isolates are isolated from one another.
- Isolates do not share memory, communication between different is made via messages. The receiving isolate processes the message using its Event Loop.
- Many Dart apps run all their code in a single Isolate, but you can have more than one if you need it.