User Tools

Site Tools


at:tutorial:appendix

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
at:tutorial:appendix [2010/05/26 19:39] – *fixed tvcutsemat:tutorial:appendix [2020/02/05 20:57] – adding elisag
Line 392: Line 392:
 The files in the ''at/lang'' directory define custom language features which mostly use AmbientTalk/2's reflective facilities to extend the language. The files in the ''at/lang'' directory define custom language features which mostly use AmbientTalk/2's reflective facilities to extend the language.
  
-==== Futures and Multifutures ==== 
  
-=== Futures ===+==== Futures ====
  
 The module ''/.at.lang.futures'' provides support for futures. Futures have already been described as part of the [[:at:tutorial:actors#futures|concurrency]] section in the tutorial. The module ''/.at.lang.futures'' provides support for futures. Futures have already been described as part of the [[:at:tutorial:actors#futures|concurrency]] section in the tutorial.
Line 417: Line 416:
 </code> </code>
  
-Finally, the futures module also provides some auxiliary functions, of which ''group:'' is often a very useful one. The ''group:'' construct groups a table of futures into a single future which is resolved with a table of values or ruined with an exception:+=== Auxilary functions in the futures module ==== 
 + 
 +The futures module also provides some auxiliary functions, of which ''group:'' is often a very useful one. The ''group:'' construct groups a table of futures into a single future which is resolved with a table of values or ruined with an exception:
  
 <code> <code>
-when: (group: [ a<-m(), b<-n() ]) becomes: { |values|+when: (group: [ a<-m()@FutureMessage, b<-n()@FutureMessage ]) becomes: { |values|
   def [aResult, bResult] := values;   def [aResult, bResult] := values;
   ...   ...
Line 426: Line 427:
 </code> </code>
  
-=== Multifutures ===+Another useful auxilary function is ''future:'' construct which returns a future which is resolved with the value passed to the 'reply' closure: 
 + 
 +<code> 
 +future: { |return| 
 +  // some computation 
 +  return(val) 
 +
 +</code> 
 + 
 +This is actually equivalent to the slightly more verbose code: 
 + 
 +<code> 
 +def [fut,res] := makeFuture(); 
 +try: { // some computation 
 +  res.resolve(val); 
 +} catch: Exception using: { |e| res.ruin(e) } 
 +fut; 
 +</code> 
 + 
 +==== Multifutures ====
  
 The module ''/.at.lang.multifutures'' provides support for multifutures. A multifuture is a future that can be resolved multiple times. We distinguish between 'bounded multifutures', which can be resolved up to a maximum number and 'unbounded multifutures' which have no upper bound. The module ''/.at.lang.multifutures'' provides support for multifutures. A multifuture is a future that can be resolved multiple times. We distinguish between 'bounded multifutures', which can be resolved up to a maximum number and 'unbounded multifutures' which have no upper bound.
at/tutorial/appendix.txt · Last modified: 2021/09/24 10:28 by elisag