       JInvitationRequest = require "./invitationrequest"
       options.sort ?= 1
       if options.batch?
-        JInvitationRequest.some {sent:$ne:true}, {limit:options.batch, sort:requestedAt:options.sort}, (err,emails)->
+        JInvitationRequest.some {sent:$ne:true}, {limit:options.batch, sort:requestedAt:options.sort}, (err, emails)->
+
+          callback null, "Done." if emails.length == 0
+          counter = 0
           daisy queue = emails.map (item)->
             ->
               continueLooping = ->
+                counter += 1
+                callback null, "Done." if emails.length == counter
                 setTimeout (-> queue.next()), 50
 
               JInvitation.sendBetaInvite email:item.email,(err,res)->

          invitation.update $set:sent:true,(err)->
          callback null,"#{invitation.email} is marked as sent."

  @sendBetaInviteFromClient = secure (client, options,callback)->

    unless client.connection.delegate?.can? 'send-invites'
      return callback new KodingError "not authorized"

    indexes         :
      code          : 'unique'
    sharedMethods   :
      static        : ['create','byCode','sendBetaInviteFromClient',
                       'grantInvitesFromClient','markAsSent',
                       'betaInviteCount']
    schema          :
      code          : String
      inviteeEmail  : String
