0

In typescript what is the simplest way to make a function wait for a callback function within?

public isLoggedIn() : boolean
{
    myCallBackFunction.getItem(access_token).then((value) => {
        return value;
    });

}

This of course doesn't compile, but how do I make it wait for the result?

  • Possible duplicate of https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – JohnnyHK Jan 11 '17 at 01:37
  • Not Ajax tried several but none work – Nabster Jan 11 '17 at 02:24
  • The async concepts are the same whether it's ajax or any other async callback. Update your question with what you're trying that isn't working. See also http://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron. – JohnnyHK Jan 11 '17 at 03:10
  • How about a simple example. Trying to keep to few lines – Nabster Jan 11 '17 at 04:20

1 Answers1

0

I am afraid but there is no such way.

If the api you are using does not provide you with synchronous counterpart of asynchronous function (in your case its getItem), you are forced to use it in asynchronous way either by consuming promises directly or using async/await.

Amid
  • 21,508
  • 5
  • 57
  • 54