https://github.com/feenkcom/pharo-futures
Abstractions for asynchronous programming in Pharo
https://github.com/feenkcom/pharo-futures
Last synced: 8 months ago
JSON representation
Abstractions for asynchronous programming in Pharo
- Host: GitHub
- URL: https://github.com/feenkcom/pharo-futures
- Owner: feenkcom
- License: mit
- Created: 2021-08-26T10:12:55.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-09-06T19:43:05.000Z (9 months ago)
- Last Synced: 2025-09-06T21:33:04.076Z (9 months ago)
- Language: Smalltalk
- Size: 464 KB
- Stars: 12
- Watchers: 9
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Asynchronous Futures & Streams
Abstractions for asynchronous programming in Pharo.
## Install
```smalltalk
Metacello new
baseline: 'Futures';
repository: 'github://feenkcom/pharo-futures:main/src';
load
```
## Futures
*Please note, that `wait` shouldn't be used in production, it is just for debugging and example purposes*
Ready:
```smalltalk
42 asAsyncFuture wait = 42
```
Computation:
```smalltalk
[ 2 seconds wait . 42 ] asAsyncFuture wait = 42
```
Map:
```smalltalk
([ 2 ] asAsyncFuture map: [ :x | x + 40 ]) wait = 42
```
Join all:
```
(AsyncJoinAllFuture futures: {
[ 42 ] asAsyncFuture.
3.14 asAsyncFuture.
9 asAsyncFuture map: [ :x | x * x ].
}) wait = #(42 3.14 81)
```
## Streams & combinators
Sequence:
```smalltalk
(1 to: 5) asAsyncStream collect wait = #(1 2 3 4 5)
```
Map:
```smalltalk
((1 to: 3) asAsyncStream map: [ :x | x * 2]) collect wait = #(2 4 6)
```
Take:
```smalltalk
((1 to: 10) asAsyncStream take: 3) collect wait = #(1 2 3)
```
Filter:
```smalltalk
((1 to: 6) asAsyncStream filter: [ :x | x even ]) collect wait = #(2 4 6)
```