Is there a way to stop in the middle of a function, and wait for a certain event before continuing?
Unfortunately I don't think it can be done. Once you begin execution of a function it will continue until the termination of the function. I believe what you might want to try is create two functions with a callback to the second function that is registered with the event you're listening for. However, it's tough to know that for sure since you haven't posted any code.
You should wrap the second half of your code in an anonymous function and attach it as an event handler:
function myFunction() {
firstHalfOfMyFunction();
eventEmitter.on('someEvent', function () {
secondHalfOfMyFunction();
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With