Async/Await/then in Dart/Flutter

前端 未结 4 989
傲寒
傲寒 2020-12-03 05:45

I have a flutter application where I am using the SQFLITE plugin to fetch data from SQLite DB. Here I am facing a weird problem. As per my understanding, we use either asyn

4条回答
  •  离开以前
    2020-12-03 06:10

    Adding to the above answers.

    Flutter Application is said to be a step by step execution of code, but it's not like that. There are a lot of events going to be triggered in the lifecycle of applications like Click Event, Timers, and all. There must be some code that should be running in the background thread.

    How background work execute:

    So there are two Queues

    1. Microtask Queue
    2. Event Queue

    Microtask Queue runs the code which not supposed to be run by any event(click, timer, etc). It can contain both sync and async work.

    Event Queue runs when any external click event occurs in the application like Click event, then that block execution done inside the event loop.

    The below diagram will explain in detail how execution will proceed.

    Note: At any given point of application development Microtask queue will run then only Event Queue will be able to run.

提交回复
热议问题