Skip to content

Commit 6b36608

Browse files
committed
fixed error in async determination
added test
1 parent 95077b3 commit 6b36608

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package gopher.channels
2+
3+
import gopher._
4+
import gopher.channels._
5+
import gopher.tags._
6+
7+
import org.scalatest._
8+
9+
import scala.language._
10+
import scala.concurrent._
11+
import scala.concurrent.duration._
12+
13+
class HofAsyncSuite extends FunSuite
14+
{
15+
16+
import scala.concurrent.ExecutionContext.Implicits.global
17+
18+
19+
test("select emulation with macroses") {
20+
21+
val channel = gopherApi.makeChannel[Int](100)
22+
23+
go {
24+
for( i <- 1 to 1000)
25+
channel <~ i
26+
}
27+
28+
var sum = 0;
29+
val consumer = go {
30+
for(s <- gopherApi.select.forever) {
31+
s match {
32+
case i: channel.read =>
33+
//System.err.println("received:"+i)
34+
sum = sum + i
35+
if (i==1000)
36+
implicitly[FlowTermination[Unit]].doExit(())
37+
}
38+
}
39+
sum
40+
}
41+
42+
Await.ready(consumer, 5.second)
43+
44+
val xsum = (1 to 1000).sum
45+
assert(xsum == sum)
46+
47+
}
48+
49+
50+
51+
52+
lazy val gopherApi = CommonTestObjects.gopherApi
53+
54+
}

0 commit comments

Comments
 (0)