4 ms·
Yeah... Well, I'm pretty sure you're wrong: 'use strict'; function getNextEvent() { return new Promise(resolve => { document.g
by tzahola 8y ago
Yeah... Well, I'm pretty sure you're wrong:
'use strict';
function getNextEvent() {
return new Promise(resolve => {
document.getElementById('button').onclick = event => resolve(event);
})
}
async function enterEventLoop() {
let event = null;
while (event = await getNextEvent()) {
alert(event);
}
}
enterEventLoop();
And thanks for recommending RxJS, but I've been using reactive programming on various platforms for the past 6 years, so I'm pretty sure it already had "clicked" for me.
- lmeyerov 8y agoNeat, I'd think the same example applies to Rx! Likewise, their library (seems to) do modular imports, which gives pay-as-you-go tree shaking. This is a good push to clarify that!
- ThJ 8y agoReassigning the event handler? That doesn't count. What if that was a WebSocket connection? Would you keep removing and adding event handlers? What if the JS engine decided to invoke the 'message' event handler 3 times in a row before invoking the next iteration of that loop? Or alternatively, what if your event loop needed to call an async function before it could process the next message, and another event fired in the meanwhile? You'd only receive the first message.