tc39/proposal-async-await

> > Btw, what's the case of exporting async function atm? Can't imagine a single one, even if it's a valid syntax.

Closed this issue · 2 comments

Btw, what's the case of exporting async function atm? Can't imagine a single one, even if it's a valid syntax.

E.g.:

fetch.js

export default async function(url) {
   var data = await request(url);

   return JSON.parse(data);
}

index.js

import fetch from './fetch';

fetch('http://example.com').then(data => {
   ...
});

if I need export the data in index.js. how can i get it?

Originally posted by @SummerXIAhaha in #74 (comment)

You can’t get the data outside a promise - so you export the promise, and you get it inside the .then (or you await the promise)

You can’t get the data outside a promise - so you export the promise, and you get it inside the .then (or you await the promise)

ok, I know it, thank you~