Dart Tutorial

Dart Tutorial Single-Page Application Architecture Dart Features Dart Installation Guide Dart Basic Program Dart Syntax Dart Keywords Dart Variables Dart Comments Dart Standard Input Output Dart Important Concepts

Data Types

Built-in Data Types Numbers Strings Booleans Lists Sets Maps Runes and Graphemes Symbols Enumerations Constants Queues

Other data types

Objects Future and stream Iterable Miscellaneous types

OPERATORS

Precedence and associativity Arithmetic operators Equality and Relational operators Type Test Operators Assignment Operators Logical Operators Bitwise and Shift Operators Miscellaneous operators

Control Flow Statements

Introduction If statement If-else statement If-else-if statement Loops Switch and case Dart Break And Continue Assert In Dart

FUNCTIONS

Dart function Types of Functions Anonymous function main( ) function Lexical scope and closure Recursion Common Collection Methods

Object Oriented Concepts

Dart Object-Oriented Concepts Dart Classes Dart Constructors Dart This Keyword Dart Super Keyword Static Members Method Overriding Dart Interfaces Inheritance Dart Abstract Classes Dart Builder Classes Dart Callable Classes

Dart Type System

Dart Type System Dart Soundness Dart Type Inference

MISCELLANEOUS

Dart Isolates Dart Typedef Dart Metadata Dart Packages Dart Generics Dart Generators Dart Concurrency Dart Unit Testing Dart Html Dom Dart URIs Dart Extends, With and Implements Keywords Dart Optional Parameters Rust Vs Dart C++ vs Dart Golang Vs Dart Dart Basics Exception Handling

Dart Concurrency

Dart concurrency allows us to run multiple or multiple components of a system at once. It issues several commands at once. Dart provides Isolates as a tool for performing compliance tasks. The concept of concurrency utilizes the unused skills of critical applications and machine hardware to make the program highly effective and increase its throughput. Dart supports concurrent programming with async-await, isolates, and classes such as Future and Stream.

How to achieve concurrency?

In Dart, Isolates help in achieving concurrency. We have discussed Dart isolates in a separate tutorial. Here we will understand the brief introduction of it. Dart isolate is a version of the Thread. But there is a key difference between the common implementation of "Thread" or "Isolates". The isolate works differently in comparison to Thread. The isolates are independent workers who do not share memory but interconnect by passing messages over channels. Since isolates complete their task by passing messages thus, it needs a way to serialize a message.

The connection between the isolates is made through a passing message as a client and server. It helps the system to take advantage of multicore microprocessors out of the box.

Dart offers a ' dart:isolate ' package to use isolate in our system. It provides a single-thread Dart code to capture solution and allows applications to make the most of available hardware.

Let's understand the following example -

Example -

import 'dart:isolate' ;   
// function containing the message to be printed
void func( var message )
{  
   print( ' We are executing this message from func( ) : ${ message } ' ) ;  
}   
void main( )
{  
   Isolate.spawn( func,' This is an isolate program ! ' ) ;  
   Isolate.spawn( func,' We are executing from main( ) function ! ' ) ;  
   Isolate.spawn( func,' These messages are referring to func( ) function ! ' ) ;  
    
   print( ' Executing from the main1( ) function ! ' ) ;  
   print( ' Executing from the main2( ) function ! ' ) ;  
   print( ' Executing from the main3( ) function ! ' ) ;  
}

Output 1 :

  Executing from the main1( ) function !
  Executing from the main2( ) function !
  Executing from the main3( ) function !
  We are executing this message from func( ) :  These messages are  
  referring to   func( ) function !
 We are executing this message from func( ) :  This is an isolate program !

Output 2 :

  Executing from the main1( ) function !

  Executing from the main2( ) function !

  Executing from the main3( ) function !

  We are executing this message from func( ) :  This is an isolate program !

  We are executing this message from func( ) :  We are executing from main( )

  function !

Output 3 :

 Executing from the main1( ) function !
 Executing from the main2( ) function !
 Executing from the main3( ) function !
 We are executing this message from func( ) :  We are executing from main(  )
function !

We are executing this message from func( ) :  This is an isolate program !

The concept of the code above is similar to dart isolate. If we use the above system many times, then the output will always be different.