-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathasync.qs
More file actions
30 lines (24 loc) · 689 Bytes
/
Copy pathasync.qs
File metadata and controls
30 lines (24 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Async/await demo
from "../stdlib/async.qs" import spawn, run, result, status, run_all
# Create tasks
task1 = spawn(fn() -> "Task 1 complete")
task2 = spawn(fn() -> "Task 2 complete")
task3 = spawn(fn() -> "Task 3 complete")
print("Task IDs:", task1, task2, task3)
print("Status before run:", status(task1))
# Run all tasks
run_all()
# Check results
print("Task 1 result:", result(task1))
print("Task 2 result:", result(task2))
print("Task 3 result:", result(task3))
print("Status after run:", status(task1))
# Individual task execution
task4 = spawn(fn() -> {
x = 10
y = 20
return x + y
})
run(task4)
print("Task 4 result:", result(task4))
print("Async demo complete")