babel / kneden

Transpile ES2017 async/await to vanilla ES6 Promise chains: a Babel plugin
ISC License
514 stars 41 forks source link

Example in readme improvement #102

Closed ndelangen closed 7 years ago

ndelangen commented 7 years ago

Maybe, I have a feeling I'm missing misunderstanding something, but it would seem to me the example in the readme is incorrect?

Example

In

async function test() {
  await db.destroy();
}

Out

function test() {
  return Promise.resolve().then(function () {
    return db.destroy();
  }).then(function () {});
}

These 2 functions behave differently: the first returns undefined, the second returns a promise?


Perhaps a better example would be:

In

async function test() {
  const result = await db.destroy();
  return result.ok;
}

Out

function test() {
  return Promise.resolve().then(function () {
    return db.destroy();
  }).then(function (result) {
    return result.ok;
  });
}

Does it work like that?

danharper commented 7 years ago
async function test() {
  await db.destroy();
}

actually returns a Promise (of undefined) - any async function returns a Promise.

image