Async function as callback

Viewed 2842

I just started using async/await and is confused on how it interacts with callback. For example,

fooMethod(function() {
    return Promise.resolve("foo");
});

vs

fooMethod(async function() { //add async keyword
    return "foo";
});

Must fooMethod be written in a specific way so that it can handle an async function as callback?

if fooMethod is a public library, how do I know that it is safe to add async keyword to the function?

FOLLOW UP

Express router,

app.get('/foo', function (req, res) {
  return res.send("foo");
});



app.get('/foo', async function (req, res) {
  return res.send("foo");
});

both of these function works, is it safe to use though?

2 Answers
Related