0

There is a condition:

let needPromise = true;

And promise function:

   getLayerId(): Promise<string> {
        return new Promise((resolve, reject) => {
             if(needPromise) {
                  //
             }
        });
    }

Somewhere I need to get string from promise:

getLayerId.then((layerId: string => {});

I need to await promise in case when needPromise true, for example opening dialog window and resolve promise instantly if needPromise = false. How to do that?

  • *resolve promise instantly* that's impossible. The reason these exists is that they are async calls and rely on an external party (http more than likely) to return before they can continue. – Liam Sep 03 '21 at 10:48
  • how about not make a primise call if needPromise if false, if needPromise is true skip getLayerId() – vaira Sep 03 '21 at 11:04
  • Could you share this example? –  Sep 03 '21 at 11:08
  • Have a look at [this example](https://stackoverflow.com/a/26600424/1048572). However, your question is really unclear, as we don't know the context – Bergi Sep 03 '21 at 11:10

0 Answers0