How to know if a function is async?

后端 未结 8 810
别跟我提以往
别跟我提以往 2020-12-01 00:55

I have to pass a function to another function, and execute it as a callback. The problem is that sometimes this function is async, like:

async function() {
          


        
8条回答
  •  囚心锁ツ
    2020-12-01 01:34

    Hei,

    Here is an approach provided by David Walsh in his blogpost:

    const isAsync = myFunction.constructor.name === "AsyncFunction";
    

    Cheers!

提交回复
热议问题