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
var endpoint = 'my/endpoint' | |
var dataPromise = getData(endpoint) | |
dataPromise.then(function(data) { | |
console.log(data) | |
}, function(error) { | |
console.error(error) | |
}) |
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
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 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
// 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 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
// Part 1 | |
function getTweetsPostsRepos(username, mainCallback) { | |
async.parallel([ | |
function(callback) { | |
getTweets(username, callback) | |
}, | |
function(callback) { | |
getPosts(username, callback) | |
}, |
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
// Part 2 | |
var username = 'seanghagstrom' | |
findLikesForPostsByUsername(username, function(err, totalLikes) { | |
if(err) { | |
console.error(err) | |
} else { | |
console.log(username + ' total number of likes: ' + totalLikes) | |
} |
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
// Part 1 | |
function findLikesForPostsByUsername(username, mainCallback) { | |
async.waterfall([ | |
function(callback) { | |
findUserByUserName(username, callback) | |
}, | |
function(user, callback) { | |
findPostsByUser(user, callback) | |
}, |
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
// Part 3 | |
var username = 'seanghagstrom' | |
getTweetsPostsRepos(username, function(err, tweetsPostsRepos) { | |
if(err) { | |
console.error(err) | |
} else { | |
console.log(username + ' has this stuff ' + tweetsPostsRepos) | |
} |
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
// Part 2 | |
function getTweetsPostsRepos(username, callback) { | |
// counter | |
getTweets(username, function(err, results) { | |
if(err) return callback(err) | |
somethingFinished(null, results) | |
}) |
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
// Part 1 | |
function getTweetsPostsRepos(username, callback) { | |
var count = 0 | |
, results = [] | |
function somethingFinished(err, result) { | |
count += 1 | |
results.push(result) | |
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
// Part 2 | |
var username = 'seanghagstrom' | |
findLikesForPostsByUsername(username, function(err, totalLikes) { | |
if(err) { | |
console.error(err) | |
} else { | |
console.log(username + ' total number of likes: ' + totalLikes) | |
} |