0

I just can’t understand how to do this function synchronously?

function (value) {
    const img = (async () => {
        const image = await base64Img.requestBase64(value);
        return image;
    })();
    return img;
}

In result I have a promise Promise { <pending> }, but I need result there. Please help :)

  • 1
    `async`/`await` are tools to manage promises. `async` functions *always* return a promise. You cannot turn asynchronous code into synchronous code. Creating a `async` function that awaits a promise and then returns its value is pointless. Just use the promise you get from `requestBase64` directly. – Quentin Jun 08 '20 at 20:23
  • but I don't need to use it directly, I have to return it from main function :( – Vladimir Babin Jun 09 '20 at 05:09
  • You. Can. Not. Do. That. – Quentin Jun 09 '20 at 17:11

0 Answers0