I'm looking to see if there is a way of taking a generic async function, such as AJAX, or web worker on message, and forcing it to behave synchronously.
First off - I really do need this behaviour, I am aware of all the arguments regarding async callbacks vs returns - but in this case, I truly need to wait for a callback.
If there is no generic solution available I'd settle for one that works purely on the Worker.prototype.onmessage
as that is the primary use case here.
I'm fairly sure the answer will be "thats not possible" but I wanted to check before surrendering.
I've already looked into promises and generators, I'd prefer not to use a third party library (I'm aware of fiber/futures for Node).
A potential use case:
function main(){
worker = new Worker("someWorker.js")
var result = worker.onmessage(function(event){
return event.data;
})
//wait for worker.onmessage
return result;
}