Created
September 29, 2017 17:40
-
-
Save rbren/a7d0ff4c5f468021adf50836fc1e45f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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