I am trying to make an Enumeratee that gets multiple EOFs because numerous Enumerators (that I do not control!) pass data through it. I only want to really forward the EOF when it's the last one (the n-th one) I encounter. I have been trying to come up with something that keeps and a counter which is increased when Input.EOF is encountered and which goes to Done whenever it equals n and increases the counter otherwise. I can't seem to increase the counter though, it is always 0, no matter the input, even if multiple EOFs have passed through it.
My code so far:
def ignoreEofs[E](maxCount: Int)(implicit ec: ExecutionContext): Enumeratee[E, E] = new CheckDone[E, E] {
val pec = ec.prepare()
def step[A](k: Input[E] => Iteratee[E, A], count: Int = 0): Input[E] => Iteratee[E, Iteratee[E, A]] = {
case Input.EOF => {
println("Counter is at: " + count)
if (count == maxCount)
Done(Cont(k), Input.EOF)
else
new CheckDone[E, E] {
def continue[A](k: Input[E] => Iteratee[E, A]) = Cont(step(k, count + 1))
} &> k(Input.EOF)
}
case in => {
new CheckDone[E, E] {
def continue[A](k: Input[E] => Iteratee[E, A]) = Cont(step(k, count))
} &> k(in)
}
}
def continue[A](k: Input[E] => Iteratee[E, A]) = Cont(step(k))
}
After running it with 2 Enumerators going into this Enumeratee, I get:
Counter is at: 0
Counter is at: 0
Why isn't my counter increased?