Is it possible to get a callback when data fed int

2019-08-10 12:57发布

问题:

I'm proxying between a TCP connection and a WebSocket, and I want to apply back-pressure to the TCP socket if the WebSocket is sending data to the browser slowly. When I receive data from the TCP socket I do:

channel.push(data.toArray)

I'd like to get an acknowledgement of when that data has been sent. How do I get that?

回答1:

I've done this:

val resumer = Enumeratee.map[Array[Byte]] { in =>
    connection ! Tcp.ResumeReading
    in
}

val enumeratorWithAck = enumerator &> resumer

It seems to work, but is it the right way to do it?