File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
src/test/scala/gopher/hofasyn Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ class HofAsyncSuite extends FunSuite
74
74
assert(r2 === Some (1 ) )
75
75
}
76
76
77
- test(" nested foreach" ) {
77
+ test(" nested option foreach" ) {
78
78
val a : Option [Int ] = Some (1 )
79
79
val b : Option [Int ] = Some (3 )
80
80
val channel = gopherApi.makeChannel[Int ](10 )
@@ -87,6 +87,32 @@ class HofAsyncSuite extends FunSuite
87
87
assert(r == 4 )
88
88
}
89
89
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
+
90
116
lazy val gopherApi = CommonTestObjects .gopherApi
91
117
92
118
}
You can’t perform that action at this time.
0 commit comments