Basic Concept of Asynchronous programming

Concept of Asynchronous Code

A Simple Synchronous Code :

void main() {
  
  // Synchronous Code 
  print("test1");
  
  
  
  for (int i = 0; i < 5; i++) {
    print('hello ${i + 1}');
  }
  
  
 
  
  testfunction();
  
  print("test3");
  
  
}


 void testfunction(){
    
   print("test2");
    
  }

Couple of asynchronous processes :

Event Loop

Futures & Callbacks

void main() {
  // Futures

  print(" Start fetching images");

  getData();

  print("Loading Images");
}

void getData() {
  //callback

  Future.delayed(Duration(seconds: 5), () {
    // Logic
    print(" Image Fetched !!!!!");
  });
}

Last updated

Was this helpful?