0

I have three functions. The calling hierarchy is like this:

function a() {
    b();
    c();
}

function b() {
    d();
}

What I want is to finish b then continue doing c. But d is asynchronous. I don't have rights to change anything in b and d. Is there any way to handle this case? Sorry for my English.

user3771751
  • 57
  • 1
  • 5
  • 6
    I think we need a bit more detail about the problem. Does `d()` take in a callback function? Does `d()` return a promise that you can chain to? – Kevin Ji Sep 29 '16 at 08:42
  • You can check `callbacks` or preferred option `promise` – Rajesh Sep 29 '16 at 08:44
  • If `d` is async, I can tell that almost async functions take callback function. If you can tell what `d` does, it'd be easier to help. – choz Sep 29 '16 at 08:44
  • 1
    This might help: http://stackoverflow.com/questions/5000415/call-a-function-after-previous-function-is-complete – Rajesh Sep 29 '16 at 08:45
  • How exactly is the async call being done? Is it using SetInterval? – kmaork Sep 29 '16 at 12:18
  • *"I don't have rights to change anything in b and d"* then your problem can't be solved. – Kevin B Sep 29 '16 at 17:43

1 Answers1

4

Almost certainly not. You need a callback, a promise, or an event.

Since you can't change b(), you can't add a callback argument to d() (assuming it accepted one in the first place) and you can't capture the return value of d() (assuming it returned a promise in the first place).

We have no way of telling if d() triggers an event on the DOM when it is done (or even if you are running the JS in a context where there is a DOM).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335