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.

6
  • 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? Commented Sep 29, 2016 at 8:42
  • You can check callbacks or preferred option promise Commented Sep 29, 2016 at 8: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. Commented Sep 29, 2016 at 8:44
  • 1
    This might help: stackoverflow.com/questions/5000415/… Commented Sep 29, 2016 at 8:45
  • How exactly is the async call being done? Is it using SetInterval? Commented Sep 29, 2016 at 12:18

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Can you add a callback when you call b?
@Tom — No. It doesn't pass any arguments to d()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.