@@ -372,27 +372,26 @@ var getWeatherData = (function(){
372372 return function ( ) {
373373 if ( ! c . refreshing && Date . now ( ) > c . refreshed + c . updateFrequency ) {
374374 c . refreshing = true ;
375- var promises = [ ] ;
376- c . locations . forEach ( function ( loc ) {
377- var deferred = Q . defer ( ) ;
378- var url = 'http://api.wunderground.com/api/' +
379- credentials . WeatherUnderground . ApiKey +
380- '/conditions/q/OR/' + loc . name + '.json' ;
381- http . get ( url , function ( res ) {
382- var body = '' ;
383- res . on ( 'data' , function ( chunk ) {
384- body += chunk ;
385- } ) ;
386- res . on ( 'end' , function ( ) {
387- body = JSON . parse ( body ) ;
388- loc . forecastUrl = body . current_observation . forecast_url ;
389- loc . iconUrl = body . current_observation . icon_url ;
390- loc . weather = body . current_observation . weather ;
391- loc . temp = body . current_observation . temperature_string ;
392- deferred . resolve ( ) ;
375+ var promises = c . locations . map ( function ( loc ) {
376+ return Q . Promise ( function ( resolve ) {
377+ var url = 'http://api.wunderground.com/api/' +
378+ credentials . WeatherUnderground . ApiKey +
379+ '/conditions/q/OR/' + loc . name + '.json' ;
380+ http . get ( url , function ( res ) {
381+ var body = '' ;
382+ res . on ( 'data' , function ( chunk ) {
383+ body += chunk ;
384+ } ) ;
385+ res . on ( 'end' , function ( ) {
386+ body = JSON . parse ( body ) ;
387+ loc . forecastUrl = body . current_observation . forecast_url ;
388+ loc . iconUrl = body . current_observation . icon_url ;
389+ loc . weather = body . current_observation . weather ;
390+ loc . temp = body . current_observation . temperature_string ;
391+ resolve ( ) ;
392+ } ) ;
393393 } ) ;
394394 } ) ;
395- promises . push ( deferred ) ;
396395 } ) ;
397396 Q . all ( promises ) . then ( function ( ) {
398397 c . refreshing = false ;
@@ -428,15 +427,14 @@ function getTopTweets(cb){
428427
429428 twitter . search ( '#travel' , topTweets . count , function ( result ) {
430429 var formattedTweets = [ ] ;
431- var promises = [ ] ;
432430 var embedOpts = { omit_script : 1 } ;
433- result . statuses . forEach ( function ( status ) {
434- var deferred = Q . defer ( ) ;
435- twitter . embed ( status . id_str , embedOpts , function ( embed ) {
436- formattedTweets . push ( embed . html ) ;
437- deferred . resolve ( ) ;
438- } ) ;
439- promises . push ( deferred . promise ) ;
431+ var promises = result . statuses . map ( function ( status ) {
432+ return Q . Promise ( function ( resolve ) {
433+ twitter . embed ( status . id_str , embedOpts , function ( embed ) {
434+ formattedTweets . push ( embed . html ) ;
435+ resolve ( ) ;
436+ } ) ;
437+ } ) ;
440438 } ) ;
441439 Q . all ( promises ) . then ( function ( ) {
442440 topTweets . lastRefreshed = Date . now ( ) ;
0 commit comments