Forked from AKM2's Pen Gravity Points.
Custom recipe to get OS X 10.10 Yosemite running from scratch, setup applications and developer environment. I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. On average, I reinstall each computer from scratch every 6 months, and I do not perform upgrades between distros.
This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.
You are encouraged to fork this and modify it to your heart's content to match your own needs.
var promise = $timeout(messageFunction, delay); | |
promise.then(function(result) { | |
ctrl.message = result; | |
}); | |
// The call to then() can also be chained. | |
$timeout(messageFunction, delay).then(function(result) { | |
ctrl.message = result; | |
}); |
server.getData(url) | |
.then(function(result) { | |
// this code block runs when the | |
// promise gets fulfilled. | |
ctrl.myData = result; | |
}) | |
.catch(function(error) { | |
// this code block runs when there | |
// is an error encountered or if the |
server.getUsername() | |
.then(function(result) { | |
return server.getProfile(result); | |
}).then(function(result) { | |
displayProfile(result); | |
return server.getProfilePicture(result.imageUrl); | |
}).then(function(result) { | |
udpateProfilePicture(result); | |
console.log('Data loaded'); | |
}).catch(function(error) { |
function getFile(url) { | |
// create a deferred object. | |
var def = $q.defer(); | |
// NOTE | |
// the $http methods success() and error() | |
// have been deprecated in favor of using then() | |
// from the standard Promises API. These are | |
// used here to show how to create a promise. | |
$http.get(url) |
// assume that getUsers returns a promise but | |
// the service may not be written in angular | |
$q.when(service.getUsers()).then(function(result) { | |
ctrl.userList = result; | |
}); | |
// $q.when() can also be useful when writing stubs | |
function getUsers() { | |
// this function is supposed to return a promise | |
// but in test, it doesn't make sense to do that |
$q.all([ | |
server.getFollowersList(), | |
server.getFollowingList(), | |
server.getTweets(), | |
server.getUserDescription() | |
]).then(function(result) { | |
// The result object will be an array | |
// with all of the results. | |
ctrl.updateFollowers(result[0]); | |
ctrl.updateFollowing(result[1]); |
function getResource(url) { | |
var resource = []; | |
var def = $q.defer(); | |
var lastProgress = 0; | |
server.openAndGet(url, function(chunk) { | |
resource.push(chunk); | |
}); | |
while(!server.txDone()) { | |
if (server.getProgress() !== lastProgress) { | |
lastProgress = server.getProgress(); |
This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.
Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:
getTweetsFor("domenic", function (err, results) {
// the rest of your code goes here.