[NAME]
ALL.dao.concurrent.asyncobject

[TITLE]
Asynchronous Object

[DESCRIPTION]

An asynchronous object is a class instance that is created with asynchronous call mode,
     
   1  async_objet = some_class( ... ) !!
     

When an asynchronous object invokes a method, it will be automatically called in
asynchronous mode, and start a tasklet and return a future value. Such tasklets 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 
calling methods of such object is just like sending messages to the object with function
parameters being the message contents. For each instance, these messages are processed
one by one in the order of receiving.

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.