This file contains 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
identity = (x) -> x |
This file contains 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
var endpoint = 'my/endpoint' | |
var dataPromise = getData(endpoint) | |
console.log(1) | |
dataPromise.then(function(data) { | |
console.log(2) | |
}) | |
console.log(3) |
This file contains 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
var endpoint = 'my/endpoint' | |
console.log(1) | |
getData(endpoint, function(err, data) { | |
console.log(2) | |
}) | |
console.log(3) |
This file contains 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
var endpoint = 'my/endpoint' | |
console.log(1) | |
getData(endpoint, function(err, data) { | |
console.log(2) | |
}) | |
console.log(3) |
This file contains 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
// Part 2 | |
var username = 'seanghagstrom' | |
findLikesForPostsByUsername(username) | |
.then(function(totalLikes) { | |
console.log(username + ' total number of likes: ' + totalLikes) | |
}) | |
.catch(function(err) { | |
console.error(err) |
This file contains 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
// Part 1 | |
function findLikesForPostsByUsername(username, callback) { | |
var promise = new Promise(function(resolver, rejector) { | |
findUserByUsername(username) | |
.then(findPostsByUser) | |
.then(findLikesByPosts) | |
.then(function(likes) { | |
var totalLikes = likes.reduce(function(x, y) { return x + y }) | |
resolver(totalLikes) |
This file contains 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
var endpoint = 'my/endpoint' | |
var dataPromise = getData(endpoint) | |
dataPromise.then(function(data) { | |
console.log(data) | |
}, function(error) { | |
console.error(error) | |
}) |
This file contains 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
var http = require('special-http') | |
function getData(endpoint) { | |
var promise = new Promise(function(resolver, rejector) { | |
http.get(endpoint).then(function(data) { | |
resolver(data) | |
}, function(err) { | |
rejector(err) | |
}) | |
}) |
This file contains 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
// Part 2 | |
var username = 'seanghagstrom' | |
getTweetsPostsRepos(username, function(err, tweetsPostsRepos) { | |
if(err) { | |
console.error(err) | |
} else { | |
console.log(username + ' has this stuff ' + tweetsPostsRepos) | |
} |
This file contains 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
// Part 1 | |
function getTweetsPostsRepos(username, mainCallback) { | |
async.parallel([ | |
function(callback) { | |
getTweets(username, callback) | |
}, | |
function(callback) { | |
getPosts(username, callback) | |
}, |