Skip to content

Instantly share code, notes, and snippets.

@rbren
Created September 29, 2017 17:40
Show Gist options
  • Save rbren/a7d0ff4c5f468021adf50836fc1e45f0 to your computer and use it in GitHub Desktop.
Save rbren/a7d0ff4c5f468021adf50836fc1e45f0 to your computer and use it in GitHub Desktop.
let hn = require('@datafire/hacker_news').create();
// Old code with promises:
Promise.resolve()
.then(_ => hn.getStories({storyType: 'top'}))
.then(storyIDs => hn.getItem({itemID: storyIDs[0]))
.then(topStory => console.log(topStory))
.catch(e => console.error(e))
// New code with async:
(async () => {
try {
let storyIDs = await hn.getStories({storyType: 'top'});
let topStory = await hn.getItem({itemID: storyIDs[0]});
console.log(topStory);
} catch (e) {
console.error(e);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment