I'm using a websocket API that streams real time changes on a remote database, which I then reflect on a local database. The operations on my side must be done in the same order (I create and update records as the data comes in).
My problem is the messages often arrive in bulk, faster than I can process them and end up out of order. Is there a way to make onmessage wait before I'm ready to process the next one ?
Here's an example of what I'm trying, without sucess:
async doSomething(ev) {
return new Promise(async (resolve, reject) => {
// database operations, etc.
resolve(true);
});
}
ws.onmessage = async (ev) => {
await doSomething();
}