File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,14 @@ fn clone_chan[T](chan[T] c) -> chan[T] {
52
52
ret unsafe:: reinterpret_cast ( cloned) ;
53
53
}
54
54
55
+ fn send[ T ] ( chan[ T ] c, & T v) {
56
+ c <| v;
57
+ }
58
+
59
+ fn recv[ T ] ( port[ T ] p) -> T {
60
+ auto v; p |> v; v
61
+ }
62
+
55
63
// Spawn a task and immediately return a channel for communicating to it
56
64
fn worker[ T ] ( fn ( port[ T ] ) f) -> rec ( task task, chan[ T ] chan) {
57
65
// FIXME: This is frighteningly unsafe and only works for
Original file line number Diff line number Diff line change @@ -33,6 +33,14 @@ fn test_join() {
33
33
assert task:: join ( failtask) == task:: tr_failure;
34
34
}
35
35
36
+ #[ test]
37
+ fn test_send_recv ( ) {
38
+ auto p = port[ int] ( ) ;
39
+ auto c = chan ( p) ;
40
+ task:: send ( c, 10 ) ;
41
+ assert task:: recv ( p) == 10 ;
42
+ }
43
+
36
44
#[ test]
37
45
fn test_worker ( ) {
38
46
task:: worker ( fn ( port[ int] p) {
You can’t perform that action at this time.
0 commit comments