Skip to content
laforge49 edited this page Aug 25, 2011 · 4 revisions

FilterSafeSeq is similar to FilterSeq, except that it works with a Safe instance rather than a function, which means that other actors can be accessed while filtering.

Test code.

class FilterSafe extends Safe {
  override def func(target: Actor, msg: AnyRef, rf: Any => Unit)(implicit sender: ActiveActor) {
    val kvPair = msg.asInstanceOf[KVPair[Int, Int]]
    rf(kvPair.value % 2 == 0)
  }
}

val range = new Range(0, 4)
val filter = new FilterSafeSeq(range, new FilterSafe)
Future(filter, Loop((key: Int, value: Int) => println(key+" "+value)))

Output.

0 0
2 2

FilterSafeSeqTest

Tutorial

Clone this wiki locally