Reputation: 989
Is there a way to stop in the middle of a function, and wait for a certain event before continuing?
Upvotes: 5
Views: 3263
Reputation: 7892
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();
});
}
Upvotes: 2
Reputation: 19635
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.
Upvotes: 6