Skip to content
Advertisement

How can I wait for a function to be called by an unknown caller?

I have a callback function that gets called by some other object which I can’t control. I need to wait until this callback function is called, I don’t care by who.

JavaScript

I found this hacky workaround, but it sucks:

JavaScript

Advertisement

Answer

Create a promise, pass its resolve function as callback to the unknown caller somehow, listen to the promise’s resolution:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement