Skip to content

Commit 2a101e8

Browse files
committed
fixed bug in select, whe quit message was delivered before processing last sum
1 parent 07728ed commit 2a101e8

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ resolvers += Resolver.sonatypeRepo("snapshots")
99

1010
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
1111

12-
scalacOptions ++= Seq("-unchecked","-deprecation", "-feature" /*, "-Ymacro-debug-lite" , "-Ydebug" , "-Ylog:lambdalift" */ )
12+
scalacOptions ++= Seq("-unchecked","-deprecation", "-feature" /* , "-Ymacro-debug-lite" , "-Ydebug" , "-Ylog:lambdalift" */ )
1313

1414
libraryDependencies <+= scalaVersion( "org.scala-lang" % "scala-reflect" % _ )
1515

src/main/scala/gopher/channels/SelectorBuilder.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ object SelectorBuilder
331331
val termName = name.toTermName
332332
// when debug problems on later compilation steps, you can create freshName and see visually:
333333
// is oldName steel leaked to later compilation phases.
334-
val newName = c.freshName(termName)
335-
//val newName = termName
334+
//val newName = c.freshName(termName)
335+
val newName = termName
336336
val tpoa = clearCaseDefOwner(name, newName, if (tp.original.isEmpty) tp else tp.original)
337337
val tpo = MacroUtil.skipAnnotation(c)( tpoa )
338338
val param = ValDef(Modifiers(Flag.PARAM), newName, tpoa ,EmptyTree)

src/test/scala/gopher/channels/MacroSelectSuite.scala

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ class MacroSelectSuite extends FunSuite
157157
test("multiple readers for one write") {
158158
import gopherApi._
159159
val ch = makeChannel[Int](10)
160-
@volatile var x1 = 0
161-
@volatile var x2 = 0
162-
@volatile var x3 = 0
163-
@volatile var x4 = 0
164-
@volatile var x5 = 0
160+
var x1 = 0
161+
var x2 = 0
162+
var x3 = 0
163+
var x4 = 0
164+
var x5 = 0
165165
val f1 = select.once{
166166
case x:ch.read =>
167167
{};
@@ -195,6 +195,31 @@ class MacroSelectSuite extends FunSuite
195195
assert(x1+x2+x3+x4+x5==1)
196196
}
197197

198+
test("fold in selector") {
199+
import gopherApi._
200+
for(i <- 1 to 100) {
201+
val ch = makeChannel[Int](10)
202+
val back = makeChannel[Int]()
203+
val quit = Promise[Boolean]()
204+
val r = select.afold(0){ (x,s) =>
205+
s match {
206+
case a:ch.read => back <~ a
207+
x+a
208+
case q:Boolean if (q==quit.future.read) => CurrentFlowTermination.exit(x)
209+
}
210+
}
211+
ch.awriteAll(1 to 10)
212+
back.aforeach{ x =>
213+
if (x==10) {
214+
quit success true
215+
}
216+
}
217+
val sum = Await.result(r, 1 second)
218+
assert(sum==(1 to 10).sum)
219+
}
220+
}
221+
222+
198223
lazy val gopherApi = CommonTestObjects.gopherApi
199224

200225
}

0 commit comments

Comments
 (0)