[NAME]
ALL.dao.concurrent.async-class

[TITLE]
Asynchronous Class

[DESCRIPTION]

An asynchronous class is a class whose instance will automatically become asynchronous i
nstance/object. And when an asynchronous object invokes a method, it will be automaticall
y called in asynchronous mode, and start a tasklet and return a future value. Such taskle
ts are queued and and executed in the order they are queued.

So such asynchronous object acts like an actor in the  actor model considering that calli
ng methods of such object is just like sending messages to the object with function param
eters being the message contents. For each instance, these messages are processed one by 
one in the order of receiving.

Asynchronous class is defined by specifying asynchronous mode with !! after the class nam
e. Here is an simple example, 
     
   1  class Account !!
   2  {
   3      private
   4  
   5      var balance = 0
   6  
   7      public
   8  
   9      routine Account( init = 0 ){
  10          balance = init
  11      }
  12      routine Withdraw( amount: int ) => enum<false,true>
  13      {
  14          if ( balance < amount ) return $false
  15          balance -= amount
  16          return $true
  17      }
  18      routine Deposit( amount: int ) => int
  19      {
  20          balance += amount
  21          return balance
  22      }
  23      routine Balance() => int
  24      {
  25          return balance
  26      }
  27  }
  28  
  29  acount1 = Account( 100 )
  30  acount2 = Account( 100 )
  31  
  32  future1 = acount1.Withdraw( 10 )
  33  if( future1.value() == $true ) future2 = acount2.Deposit( 10 )
  34  
  35  future3 = acount1.Deposit( 20 )
  36  
  37  io.writeln( 'Balance in account1:', acount1.Balance().value() )
  38  io.writeln( 'Balance in account2:', acount2.Balance().value() )
     

Like calling mt.start(), calling a method on an asynchronous object will return a future 
value, which can be used to check the status of the asynchronous call.