Skip to content

Commit 383b95c

Browse files
committed
Update docs
1 parent 589e174 commit 383b95c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,30 @@ of the program to fork in two different threads of execution.
734734
735735
```js
736736
async loadImage(n: String): Promise<?> {
737-
return await ImageIO.read(n);
737+
if(!cache.contains(n)) {
738+
return await ImageIO.read(n);
739+
}
740+
return cache.get(n); // no need to go async
741+
}
742+
```
743+
744+
All async functions can cascade such that if an async function calls another it is suspended until the function
745+
being called completes, at which point it will resume from the call site. For convenience closures can also
746+
be asynchronous.
747+
748+
```js
749+
let loadImage = async (n: String) -> ImageIO.read(n);
750+
```
751+
752+
Here there is no need to specify the await keyword as expression based asynchronous closures have an implicit await.
753+
For closures that have more than a single expression you must specify which statements are asynchronous.
754+
755+
```js
756+
let loadImage = async (n: String) -> {
757+
if(!cache.contains(n)) {
758+
return await ImageIO.read(n);
759+
}
760+
return cache.get(n); // no need to go async
738761
}
739762
```
740763

0 commit comments

Comments
 (0)