Created
January 17, 2014 11:43
-
-
Save aniketbhatnagar/8472108 to your computer and use it in GitHub Desktop.
Enumerator.onDoneEnumerating doesn't get called when iteratee is done enumerating in play 2.2.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object EnumeratorFun extends App { | |
var counter: Int = 0 | |
val enumerator = Enumerator.generateM[Int]({ | |
val ret: Option[Int] = if (counter < 5) { | |
counter += 1 | |
Some(counter) | |
} else None | |
Future(ret) | |
}) | |
enumerator.onDoneEnumerating(println("Done enumerating. This should get called when its final input has been consumed by Iteratee")) | |
val iteratee = Iteratee.foreach[Int](println(_)) | |
val runComplete = enumerator(iteratee) | |
Await.result(runComplete, Duration.Inf) | |
println("Finished waiting for iteratee to run on enumerator") | |
} |
As per comments from Gary, onDoneEnumerating does not modify the existing enumerator, but creates a new enumerator which runs the callback when done (or at an error). Updated case (that works):
object EnumeratorFun extends App {
var counter: Int = 0
val enumerator = Enumerator.generateM[Int]({
val ret: Option[Int] = if %28counter < 5%29 {
counter += 1
Some%28counter%29
} else None
Future%28ret%29
})
val enumWithOnDone = enumerator.onDoneEnumerating(println("Done enumerating. This should get called when its final input has been consumed by Iteratee"))
val iteratee = Iteratee.foreachInt
val runComplete = enumWithOnDone(iteratee)
Await.result(runComplete, Duration.Inf)
println("Finished waiting for iteratee to run on enumerator")
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample case for playframework/playframework#2278