1

I have a method 'getAssetByIdAsync(assetId)'

export const getAssetByIdAsync = (assetId) => {
    const asset = assets.find((a) => a.id === assetId);

    if (!asset) {
        throw new Error("Asset not found" + assetId);
    }

    return new Promise((resolve) => setTimeout(() => resolve(asset), 500));
};

this method returns a Promise.

I have created a method 'renderMasterThumb(masterAssetId)'

const renderMasterThumb = async (masterAssetId) => {
    const masterAsset = await getAssetByIdAsync(masterAssetId);
    const path = masterAsset.path;
    return path;
  };

I was hoping that this method would return the .path property of masterAsset, but it turns out that the method return a Promise object.

If I print through a console.log(path), I get the right value: 'bart.jpg'

How can I make the renderMasterThumb method return an image path instead of a Promise Object.

thanks for your help,

Anthony

Toontje
  • 1,415
  • 4
  • 25
  • 43
  • [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Andreas Jul 02 '20 at 10:17
  • Can you please add the code of getAssetByIdAsync() – DevLoverUmar Jul 02 '20 at 10:19
  • 1
    Functions annotated as `async` will always return a Promise, that's the whole idea behind `async-await` – Lennholm Jul 02 '20 at 12:02

0 Answers0