Utilizing SignalR to initiate lengthy computations on the server and notify the client when the results are ready. The input bindings consist of an HTTP request.
Desire to send multiple messages to update the client on various stages of the process (e.g., start of computation, end of computation, etc.).
Tried pushing individual messages to context.bindings.signalRMessages but noticed they all get sent together at the end of the entire process. Is there a method to send multiple messages at different points in time?
Another issue is that the client's HTTP request remains in a frozen state until the process completes. Would like to provide an immediate response early on, as the response will be received through a signalR message.
Below is the server-side code:
module.exports = async function(context, req) {
let ID = context.bindingData.invocationId;
context.bindings.signalRMessages = [];
const messageQueue = context.bindings.signalRMessages;
var postMessage = (message) => {
message.userId = req.query.userId;
message.isPrivate = true;
messageQueue.push(message);
};
let preProcessData = preProcess(req.body.input);
let startMessage = {
"target": "optimStart",
"arguments": [{ preProcessData: preProcessData }]
};
postMessage(startMessage); // <<<< I want this one to be sent immediately
try {
let optimOutput = await computeOptim(req.body.input, ID); // that's the long process
let response = {
optimId: ID,
optimOutput: optimOutput
};
let optimCompleteMessage = {
"target": "optimComplete",
"arguments": [response]
};
postMessage(optimCompleteMessage);
} catch (err) {
// ....
}
};
Could it be an error in my implementation or is it simply not possible?
Appreciate any insights!