Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How would I convert this promise to an async / await function?

Here's my Promise:

$(document).ready(function() {
	const fetchData = () => {
	  const promise = new Promise((resolve, reject) => {
		setTimeout(() => {
		  resolve("Loose Cannon Fitness");
		}, 100);
	  return promise;

	setTimeout(() => {
	  console.log("Smith and Gone");
	  .then(text => {
	}, 200);


Open in new window

How would I convert that to an "async / await" dynamic?
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust



As always, thank you for a thorough explanation!

What you've got works, but I've got one more related question and let me qualify it by saying that at this point, it's not about practical application as much as it's for my own edification.

Could I write "fetchData" as an anonymous function? Not that I would necessarily do that in a practical setting, but I was curious.

You'll find that question at

As always, thank you for your time, bud!
You are welcome. (will respond in your other thread)
Rock on!