Using async await on custom promise

后端 未结 3 2032
情深已故
情深已故 2020-12-21 07:59

Im trying to use async await on a function that returns a promise but the out put im getting is Promise { }. In here im using f

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-21 08:36

    convertFiletoPDF() 
    

    This function run and returned a Promise. This is fine.

    myfunc()
    

    Lets say myfunc takes 10 seconds. Javascript starts to wait newly created thread result from libuv via event loop mechanism. So, Javascript says, "That one is async, I will not wait, when it finishes it will let me know and i will run my then callback and then I will proceed with its output."

    Javascript keeps his promise. Tries to run next below lines. myFunch is still working. Output is not ready yet. Returns undefined.

    let res = myfunc(file);
    console.log(res);
    

    You get undefined.

提交回复
热议问题