Skip to content

Commit 45c5c1d

Browse files
committed
examples: Added a new virtual threads example
1 parent 2cd3651 commit 45c5c1d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

examples/virtual3.pics

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
import std.io
3+
import std.virtual
4+
import std.string
5+
6+
getUser :: (id = 0) = Virtual::task(|_| -> do {
7+
Virtual::sleep(1000 * 3)
8+
user := {name: "User" + id, id: id}
9+
user
10+
})
11+
12+
getProfile :: (id = 0) = Virtual::task(|_| -> do {
13+
user := getUser(id)
14+
profile := {kind: "Profile", user: user}
15+
profile
16+
})
17+
18+
printProfile :: (kind, user) = IO::println(String::format("%s := {name: %s}", [kind, user.name]))
19+
20+
21+
IO::println("Start")
22+
23+
profile_future := getProfile(100)
24+
IO::println(profile_future)
25+
26+
profile := profile_future.await
27+
user := profile.user.await
28+
29+
printProfile(profile.kind, user)
30+
31+
32+

0 commit comments

Comments
 (0)