Skip to content

Commit 9afdcd2

Browse files
committed
Add test
1 parent 44ac53c commit 9afdcd2

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import io
2+
import io/error
3+
import io/network
4+
import io/time
5+
import bytearray
6+
7+
def main() = {
8+
with on[IOError].panic
9+
val listener = listen("127.0.0.1", 8080, 1000);
10+
spawn(box {
11+
with on[IOError].panic
12+
accept(listener, box { connection =>
13+
with on[IOError].panic
14+
println("accepted")
15+
val message = "hello world"
16+
var buffer = bytearray::fromString(message)
17+
write(connection, buffer, 0, buffer.size())
18+
close(connection)
19+
})});
20+
21+
println("started")
22+
23+
val results = array::build(2) { i =>
24+
promise(box {
25+
with on[IOError].result
26+
wait(1000)
27+
val connection = connect("127.0.0.1", 8080)
28+
println("connected")
29+
var buffer = bytearray::allocate(4096)
30+
val number = read(connection, buffer, 0, 4096)
31+
close(connection)
32+
println("closed " ++ number.show)
33+
number
34+
})
35+
};
36+
37+
println("spawned")
38+
39+
var total = 0;
40+
results.foreach { number =>
41+
println("awaiting")
42+
total = total + number.await.value
43+
println("awaited")
44+
};
45+
46+
shutdown(listener)
47+
48+
println(total)
49+
}

0 commit comments

Comments
 (0)