Skip to content

Commit 2083eae

Browse files
committed
std: Add module for virtual threads
1 parent 105f0c3 commit 2083eae

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

std/fs/file.pics

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
import std.sys { System { todo } }
3+
4+
module File {
5+
function new() = todo("Implement the file functions")
6+
}
7+
8+

std/virtual/vthread.pics

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11

2-
2+
// Module: Virtual
3+
// Contains functions for working with threads
34
module Virtual {
4-
function task(fx) = pic_nat_task(fx)
5-
function sleep(fx) = pic_nat_sleep(fx)
6-
function await(task) = task.await
7-
}
85

6+
// Function: task
7+
// Executes a closure in a virtual thread
8+
//
9+
// Parameters:
10+
// fx - The closure to execute
11+
//
12+
// Returns:
13+
// A handle to the thread executing.
14+
// This handle can be used to get the result of the closure
15+
function task(fx) = pic_nat_task(fx)
16+
17+
18+
// Function: sleep
19+
// Pauses the current thread
20+
//
21+
// Parameters:
22+
// ms - Amount to pause by, in milliseconds
23+
//
24+
// Returns:
25+
// A Unit value
26+
function sleep(ms) = pic_nat_sleep(ms)
27+
28+
29+
// Function: await
30+
// Waits for the virtual thread to finish and gets the result
31+
//
32+
// Parameters:
33+
// task - The task handle
34+
//
35+
// Returns:
36+
// The result of the thread.
37+
function await(task) = task.await
38+
}
939

1040

0 commit comments

Comments
 (0)