diff src/google.coffee @ 17:a52b5b244e51

removed unnecessary underscore and replaced it with async
author Mathias Gebbe <mgebbe@intevation.de>
date Fri, 13 Jun 2014 15:18:36 +0200
parents ccf1d9e741bd
children c552faae9c1c
line wrap: on
line diff
--- a/src/google.coffee	Thu Jun 12 20:58:06 2014 +0200
+++ b/src/google.coffee	Fri Jun 13 15:18:36 2014 +0200
@@ -49,7 +49,7 @@
         (callback) ->
           getStream(user, friend, callback)
         (stream, callback) ->
-          _.each stream.items, (post) ->
+          async.each stream.items, ((post, cb) ->
             async.waterfall [
               (callback) ->
                 FromESN.search {uid: post.id + "@google_to_" + me, recipientUser: me}, callback
@@ -76,8 +76,9 @@
             ], (err, result) ->
                  #console.log err
                  #console.log result
-          return
-          callback null, null
+                 cb()
+          ), (err) ->
+            callback null, 'done'
       ], (err,  result) ->
         #console.log 'done.'
       callback null, 'done'
@@ -86,7 +87,6 @@
         console.log 'one post fail to process'
       else
         console.log 'all google friends processed'
-      return
   return
 
 
@@ -146,17 +146,22 @@
     res.on "end", () ->
       async.waterfall [
         (callback) ->
-          users = JSON.parse(decodeURI(data))
-          return if (users.error?)
-          callback null,users
+          try
+            users = JSON.parse(decodeURI(data))
+            return if (users.error?)
+            callback null,users
+          catch err
+            console.log 'getFriends error'
+            return
         (users, callback) ->
           EdgeControl.removeEdges(me,'@google')
-          _.each users.items, (user) ->
+          async.each users.items, ((user, cb) ->
             if user.id?
               friends.push(user.id)
               Routes.updateUserDB(user.id+'@google',user.displayName,user.displayName,user.url,user.image.url)
               EdgeControl.addEdge(me,user.id+'@google')
-          callback null, friends
+          ), (err) ->
+            callback null, friends
       ], (err, friends) ->
         callback null, friends
        return
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)