Hi everyone,
I would like to use Cinemas job system to send multiple HTTP requests asynchronous / in parallel. I have created a custom HttpRequestJob
which will return a custom HttpResponse
struct.
After the job will be enqueued (and therefore started) I can sucessfully ask for the HTTP response with:
HttpResponse response = httpRequestJob.MoveResult() iferr_return;
Instead of asking the job for a result I would like to get a callback function called after the job has finished, because this would better fit into our current plugin architecture. I would like to add an observer to httpRequestJob.ObservableFinished()
.
The problem is:
I will not get the result from the job (an HttpResponse
object) passed to the observer / callback function. The callback function has the following signature:
static void RequestCallback(HttpResponse httpResponse)
It seems the following does not work because the callback function has a parameter:
httpRequestJob.ObservableFinished().AddObserver(RequestCallback);
It also does not work when I provide a lambda with a HttpResponse
or const HttpResponse&
argument as an observer:
httpRequestJob.ObservableFinished().AddObserver([](HttpResponse response)
{
// Doing something with the response ...
}) iferr_return;
It seems AddObserver()
will only take a callback function without arguments in this case, but this way I cannot do any meaningful work with the observer.
Any ideas how I can get access to the job result in an observer? Thanks in advance!
Best regards,
Tim
PS: The job looks something like this:
class HttpRequestJob : public maxon::JobInterfaceTemplate<HttpRequestJob, HttpResponse>
{
public:
HttpRequestJob() { };
HttpRequestJob(
const String &url,
const String &method,
const String &body,
const maxon::DataDictionary &headers)
{
_url = url;
_method = method;
_body = body;
_headers = headers;
}
maxon::Result<void> operator ()()
{
iferr (HttpResponse httpResponse = SendHttpRequest(_url, _method, _body, _headers, _description))
{
ApplicationOutput("@", err);
return err;
}
return SetResult(std::move(httpResponse));
}
const maxon::Char* GetName() const
{
return "HttpRequestJob";
}
private:
maxon::String _url;
maxon::String _method;
maxon::String _body;
maxon::DataDictionary _headers;
};