question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Convert Promise to async function

See original GitHub issue

Input:

var promise = function() {
  return new Promise((resolve) => function() {
    setTimeout(resolve, 200, 4);
  });
};
var aF = function() {
  return new Promise(resolve => {
    promise.then((data) => {
      resolve(data);
    });
  });
}

Expected output:

let promise = () => new Promise((resolve) => function() {
    setTimeout(resolve, 200, 4);
  });
};

let aF = async () => {
  return await promise;
};

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:8
  • Comments:14

github_iconTop GitHub Comments

2reactions
nenecommented, Dec 30, 2016

@tunnckoCore Ah, I guess my comment was pretty ambiguous. My concern wasn’t about babylon, but about Recast supporting the things babylon supports.

0reactions
jedwards1211commented, Apr 16, 2020

I’m pleased to announce a new codemod I developed for this. It’s still a bit of a work in progress, but it’s getting pretty baller. You may be interested in integrating it into lebab. (Although the README shows how to use it with jscodeshift, the transform is actually implemented with pure babel 7).

https://github.com/codemodsquad/asyncify

Right now if you want to see examples look in the tests. I’ll plan on making a try-it site in the next few days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert Promise-Based Chain to Async/Await with VS Code
Converting Promises to Async/Await with Visual Studio Code · First, select the code that conatins the Promise.then() calls, · Next, click the ...
Read more >
Converting promises to async/await - Javascript - Stack Overflow
I have a dataService function in React that does my API fetching. I tried converting to async/await block but seem to hit a...
Read more >
Migrating from Promise chains to Async/Await - AfterAcademy
Introduces Async/Await and compare it with Promises. We shall discuss migrating your from Promise Chains to Async/Await .
Read more >
Convert A Promise To ASYNC/AWAIT - DEV Community ‍ ‍
This is a simple function that returns a promise. The promise resolves to a value of type string, and of value "resolved" after...
Read more >
Automatically convert Promise.then() into async/await - VS Code
Focus on some code which uses .then() with Promise related code · Click the lightbulb icon which appears in the line gutter ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found