Skip to content

Commit 753887c

Browse files
committed
added check for channel.foreach
1 parent f4d0eee commit 753887c

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/test/scala/gopher/hofasyn/HofAsyncSuite.scala

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class HofAsyncSuite extends FunSuite
7474
assert(r2 === Some(1) )
7575
}
7676

77-
test("nested foreach") {
77+
test("nested option foreach") {
7878
val a:Option[Int] = Some(1)
7979
val b:Option[Int] = Some(3)
8080
val channel = gopherApi.makeChannel[Int](10)
@@ -87,6 +87,32 @@ class HofAsyncSuite extends FunSuite
8787
assert(r == 4)
8888
}
8989

90+
test("option flatMap") {
91+
val channel = gopherApi.makeChannel[Int](10)
92+
val map = Map(1->Map(2->channel))
93+
val fout = go {
94+
for (x <- map.get(1);
95+
ch <- x.get(2)) yield ch.read
96+
}
97+
val fin = channel.awrite(1)
98+
val r = Await.result(fout, 5.second)
99+
assert(r == Some(1))
100+
}
101+
102+
test("channels foreach ") {
103+
val channels = gopherApi.makeChannel[Channel[Int]](10)
104+
val fin = go {
105+
for(ch <- channels) {
106+
ch.awrite(1)
107+
}
108+
}
109+
val ch = gopherApi.makeChannel[Int](10)
110+
channels.awrite(ch)
111+
val fout = ch.aread
112+
val r = Await.result(fout, 5.second)
113+
assert(r == 1)
114+
}
115+
90116
lazy val gopherApi = CommonTestObjects.gopherApi
91117

92118
}

0 commit comments

Comments
 (0)