Support #7426
openWt::Response::createContinuation() with streaming
0%
Description
Hello. I am trying to achieve a never ending streaming server with WResource and ResponseContinuation.
I noticed that `ResponseContinuation::createContinuation()` always returns the same pointer address in during an instance of a `WResource::handleRequest()` where I create a continuation each time.
Is it safe to pass this `ResponseContinuation` pointer to an asynchronous thread?
(The asynchronous thread would put a reference to some data in `ResponseContinuation::setData()` and then call `ResponseContinuation::haveMoreData()` every time that data updated so the `WResource::handleRequest()` could publish the data from it's `ResponseContinuation::data()` to the event-stream)
When the client cuts off the connection, `WResource::handleAbort()` will remove the ResponseContinuation from the asynchronous thread.
Updated by Roel Standaert about 4 years ago
I believe it is intended that you can use it like that. We've done a streaming resource before, but we're really lacking a streaming resource example.
Updated by Roel Standaert about 4 years ago
So the data()
and setData()
is for associating some context information with the continuation, but that is not how you would actually set the data to be sent, since data()/setData()
is not synchronized. You will have to devise your own thread safe way of passing data from your asynchronous thread to the handleRequest
code.
haveMoreData()
should be thread safe, though, and it should be safe to pass the ResponseContinuation
to another thread.
Updated by jordan heath about 4 years ago
Roel Standaert wrote:
So the
data()
andsetData()
is for associating some context information with the continuation, but that is not how you would actually set the data to be sent, sincedata()/setData()
is not synchronized. You will have to devise your own thread safe way of passing data from your asynchronous thread to thehandleRequest
code.
haveMoreData()
should be thread safe, though, and it should be safe to pass theResponseContinuation
to another thread.
Awesome, that is what I gathered from reading the open source code, but I just wanted to make sure before I was 100%. Thank you for your response.