Skip to content

feenkcom/pharo-futures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asynchronous Futures & Streams

Abstractions for asynchronous programming in Pharo.

Install

Metacello new
   baseline: 'Futures';
   repository: 'github://feenkcom/pharo-futures:main/src';
   load

Futures

Ready:

42 asFuture wait = 42

Computation:

[ 2 seconds wait . 42 ] asFuture wait = 42 

Map:

([ 2 ] asFuture map: [ :x | x + 40 ]) wait = 42

Join all:

(AsyncJoinAllFuture futures: { 
   [ 42 ] asFuture.
   3.14 asFuture.
   9 asFuture map: [ :x | x * x ].
}) wait = #(42 3.14 81)

Streams & combinators

Sequence:

(1 to: 5) asAsyncStream collect wait = #(1 2 3 4 5)

Map:

((1 to: 3) asAsyncStream map: [ :x | x * 2]) collect wait = #(2 4 6)

Take:

((1 to: 10) asAsyncStream take: 3) collect wait = #(1 2 3)

Filter:

((1 to: 6) asAsyncStream filter: [ :x | x even ]) collect wait = #(2 4 6)

About

Abstractions for asynchronous programming in Pharo

Resources

License

Stars

Watchers

Forks

Packages

No packages published