On Mon, 10 Mar 2014 21:21:51 GMT, Craig Dillabaugh wrote:

However, it seems that the message written to res.bodyWriter is not returned to the client until my 'longProcess' function terminates.

Is there any way to achieve what I am trying to do? Alternately, I am happy to hear of any better approaches to dealing with this problem.

It looks like you've run into a side effect of Nagle's Algorithm. Even though you finalize the stream, the underlying TCP/IP buffer in the kernel is only flushed when it reaches a certain number of bytes or when the connection is closed.

I think you can get around this by using cast(TCPConnection)(res.bodyWriter).tcpNoDelay = true;. However, I have not tested this and I don't think there's any documentation about it.

The more straightforward method is to run this long process in a worker task and to query the status in a separate connection (through a shared variable) or to feed it through a Websocket (more complicated..).

Good luck