Skip to content

Instantly share code, notes, and snippets.

@gnarf
Forked from dmethvin/deferreds_pipe
Created October 13, 2011 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnarf/1284935 to your computer and use it in GitHub Desktop.
Save gnarf/1284935 to your computer and use it in GitHub Desktop.
Use of deferreds and pipe
fetchCurrentPosition()
.then(updateLocationDisplay)
.pipe(fetchWeatherAtThisLocation)
.then(updateWeatherDisplay)
.pipe(determineWeatherType)
.then(updateRecommendations)
.then(updateAppTile);
function fetchCurrentPosition()
{
var deferred = $.Deferred();
navigator.geolocation.getCurrentPosition(
function( position ) {
deferred.resolve( position );
},
function( error ) {
reportError("geolocation", error);
deferred.reject( error );
}
);
return deferred.promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment