I am using node-red flow and inside I have a node function that does something like this:
s3.getObject(params, function(err,data) {
if (!err && data && data.Body) {
msg.s3aka = data.Body.toString()
}
});
while (true) {
if (msg.s3aka)
break;
let start = new Date().getTime();
while (true) { // delay 100ms
if ((new Date().getTime() - start) > 100){
break;
}
}
}
return msg;
So I wait for the result (msg.s3aka) to be set to return the msg. This looks ugly and I can't use async/await inside node function (not support ES 7). If I use Promise the last line (return msg) will be executed before msg.s3aka is set. So is there a better way to do this using vanilla javascript?
Edit: This is not solved by How do I return the response from an asynchronous call? since it is specific to node-red. I tried various ways including using date, async await, promise. I solved this by using node.send(msg) in the callback.