blob: fffcbe9977c26e57347584db5796af1c87fc1503 (
plain) (
blame)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package escale
import utest._
import scala.concurrent.ExecutionContext.Implicits.global
import escale.syntax._
import scala.concurrent.Future
object SyntaxTest extends TestSuite {
val tests = Tests {
"!< and !<" - {
val ch1 = chan[Int]()
val ch2 = chan[Int](1)
go {
ch1 !< 1
ch1 !< 2
ch1 !< 3
}
go {
var sum = 0
sum += !<(ch1)
sum += !<(ch1)
sum += !<(ch1)
ch2 !< 4
sum += !<(ch2)
assert(sum == 10)
}
}
"select syntax" - {
def run(): Future[String] = go {
val Ch1 = chan[Int]()
val Ch2 = chan[Int]()
go {/*Thread.sleep(1);*/ Ch1 !< 1}
go {/*Thread.sleep(1);*/ Ch2 !< 1}
select(Ch1, Ch2) match {
case (Ch1, _) => "ch1 was first"
case (Ch2, _) => "ch2 was first"
}
}
run()
}
}
}
|