0

I want to call a function A that returns an int. function A calls function B, which changes some values needed by function A to correctly proceed. Something like this:


global variable value;

function A(){
   // do some stuff
   B();
   //do some stuff
   return value;
}

function B(){
   //does some stuff that times time
   //changes value
}

My problem is that function A returns before function B finishes. I have looked at callbacks but that doesn't seem to be what I am looking for. Is there a practical way to achieve this ? Thanks in advance.

  • 1
    "some stuff" doesn't tell us much about what's happening. Do you have a more concrete example? If you're performing an asynchronous operation then you'd either need to `await` it or use a callback. – David Jul 02 '20 at 15:18
  • what are your "//do some stuff"s? maybe you're doin' something asynchronous and you need to use [async/await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) – Vahe Yavrumian Jul 02 '20 at 15:19
  • If A is returning before B is finished processing, that means that something is running asynchronously. The way to fix this is to use `await [promise]` – ControlAltDel Jul 02 '20 at 15:20

0 Answers0