Placing the async keyword before a function makes the function return a Promise.
async function myFunction() { return “Hello”; } |
Is the same as:
function myFunction() { return Promise.resolve(“Hello”); } |
This is how you can use a Promise:
myFunction().then( function(value) { /* code if successful */ }, function(error) { /* code if some error */ } ); |
async function myFunction() { return “Hello”; } myFunction().then( function(value) {myDisplayer(value);}, function(error) {myDisplayer(error);} ); |
Or more simply, if you expect a standard value (a normal response, not an error):
async function myFunction() { return “Hello”; } myFunction().then( function(value) {myDisplayer(value);} ); |