threads and dart
I've spent a lot of time thinking threads, and this is my conclusion (for the time being).
They call dart a single-threaded programming language. But what does that mean? Well, as far as I understand it, a thread makes sense only in the context of a cpu that processes instructions and instructions (or lines of code) that has to be processed sequentially.
When they say dart is a single-threaded language, it means that dart moves through the lines of code, one after another, moving to the next line only after processing the current line of code or instruction. When you've got code like this that just has to be processed sequentially, then there's not much a kernel can do to optimize, because if code can't be broken down into multiple threads the kernel can't utilize all the cores and hyperthreading capabilities of the CPU.
So being a single-threaded language, if one line of code takes a particularly long time, your flutter app appears frozen while its being executed. So while the CPU works on this line of code, the buttons on your flutter app won't work, you won't be able to enter anything into textfields. This is an undesirable situation, but dart has a solution for this which doesn't involve creating another thread.
The solution is to make the time consuming operation a separate function that returns a Futurethen
method to make use of flutter's event looop. You see a program you write in dart doesn't stop running even after processing line of the main function, if the event loop is anticipating an event.
Just like the sequence of instructions that are fed through the thread to the CPU, events are fed to the event loop to the event event que. At this point I can't really tell if the two are really distinct, a thread and the event loop that is. Its possible to think they're the same thing: the event loop then does both synchronous computations and executes the then clause when the result of an asynchronous operation finally returns a result.
Visualize threads as conveyor belts holding lines of instruction leading to the CPU. Its begins with instructions specified in the main function and ends there too. But its possible to instruct dart vm to expect events and wait for them to appear in the thread or feed or event queue and respond to it.