RosettaCodeData/Task/Synchronous-concurrency/Scala/synchronous-concurrency.scala

25 lines
489 B
Scala
Raw Permalink Normal View History

2014-01-17 05:32:22 +00:00
case class HowMany(asker: Actor)
2013-04-11 01:07:29 -07:00
val printer = actor {
var count = 0
2014-01-17 05:32:22 +00:00
while (true) {
receive {
case line: String =>
print(line); count = count + 1
case HowMany(asker: Actor) => asker ! count; exit()
2013-04-11 01:07:29 -07:00
}
2014-01-17 05:32:22 +00:00
}
2013-04-11 01:07:29 -07:00
}
2014-01-17 05:32:22 +00:00
def reader(printer: Actor) {
scala.io.Source.fromFile("c:\\input.txt").getLines foreach { printer ! _ }
2013-04-11 01:07:29 -07:00
printer ! HowMany(
actor {
2014-01-17 05:32:22 +00:00
receive {
case count: Int => println("line count = " + count)
2013-04-11 01:07:29 -07:00
}
})
}
reader(printer)