Skip to content

Instantly share code, notes, and snippets.

@dpalita
Created February 4, 2018 13:42
Show Gist options
  • Save dpalita/24272bd9f938767dbaf61b7adb10303a to your computer and use it in GitHub Desktop.
Save dpalita/24272bd9f938767dbaf61b7adb10303a to your computer and use it in GitHub Desktop.
const fetchNews = (subject: string): Promise<News[]> => {
return fetch('http://newsApi?subject=' + subject)
// promise
.then(res => res.text() /* re promise ^^ */)
}
const trumpNews = fetchNews('Trump')
const kimNews = fetchNews('Kim Jong-Un')
trumpNews.then(news => readNewsAndLaugh(news))
kimNews.then(news => readNewsAndLaugh(news))
Promise.all(trumpNews, kimNews)
.then(newsArray => readNewsAndCry(flatten(newsArray)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment