function visitNotifications(startKey, visitor) {
    var deferred = $.Deferred();
    var request = _(requestTemplate).clone();
    request.limit = 50;
    if (startKey) {
      request.start_key = String(startKey);
    }
    
    // Dispatches a single query to the server.  
    function sendQuery() {
      serviceRequest('query_notifications', request).done(doneQuery).fail(failQuery);
    }
    
    // Invokes the callback with the result of a completed query.  If there are 
    // more results on the server which were paged, creates a continuation function
    // which will query the next page and returns it.
    function doneQuery(response) {
      var isLastQuery = (response.notifications.length < request.limit);
      
      // Send out request for the next page of data, if it exists.
      if (!isLastQuery) {
        request.start_key = response.last_key;
        sendQuery();
      } 
      
      // Invoke the visitor on each notification received.
      _(response.notifications).each(visitor);
      
      // If this was the last page of the query, resolve this method's promise.
      if (isLastQuery) deferred.resolve();
    }
    
    function failQuery(jqHxr, textStatus) {
      deferred.reject("Error from visitNotifications: " + textStatus);
    }
    
    sendQuery();
    return deferred;
  }
/**
   * Queries the service for a list of notifications for the current user and invokes the given
   * callback once for each notification.  Only notifications occurring after the given startKey 
   * are queried.
   *
   * @memberof viewfinder.query
   * @param {String|Number} startKey Starting key for the notification query.  Only notifications newer than the
   *  given key will be visited.
   * @param {Function}  Visitor function which will be invoked once for each viewpoint
   *  followed by the current user.
   * 
   * @returns {jQuery.Deferred} A jQuery deferred object which will resolve when all notifications
   *  have been visited.
   */
Queries the service for a list of notifications for the current user and invokes the given
callback once for each notification.  Only notifications occurring after the given startKey
are queried.

@memberof viewfinder.query
@param {String|Number} startKey Starting key for the notification query.  Only notifications newer than the
given key will be visited.
@param {Function}  Visitor function which will be invoked once for each viewpoint
followed by the current user.

@returns {jQuery.Deferred} A jQuery deferred object which will resolve when all notifications
have been visited.
Queries the service for a list of notifications for the current user and invokes the given callback once for each notification . Only notifications occurring after the given startKey are queried . @memberof viewfinder . query @param { String|Number } startKey Starting key for the notification query . Only notifications newer than the given key will be visited . @param { Function } Visitor function which will be invoked once for each viewpoint followed by the current user . @returns { jQuery . Deferred } A jQuery deferred object which will resolve when all notifications have been visited .
function visitNotifications(startKey, visitor) {
    var deferred = $.Deferred();
    var request = _(requestTemplate).clone();
    request.limit = 50;
    if (startKey) {
      request.start_key = String(startKey);
    }
    function sendQuery() {
      serviceRequest('query_notifications', request).done(doneQuery).fail(failQuery);
    }
    function doneQuery(response) {
      var isLastQuery = (response.notifications.length < request.limit);
      if (!isLastQuery) {
        request.start_key = response.last_key;
        sendQuery();
      } 
      _(response.notifications).each(visitor);
      if (isLastQuery) deferred.resolve();
    }
    function failQuery(jqHxr, textStatus) {
      deferred.reject("Error from visitNotifications: " + textStatus);
    }
    sendQuery();
    return deferred;
  }
function visitNotifications ( startKey , visitor ) { var deferred = $ . Deferred ( ) ; var request = _ ( requestTemplate ) . clone ( ) ; request . limit = 50 ; if ( startKey ) { request . start_key = String ( startKey ) ; } function sendQuery ( ) { serviceRequest ( 'query_notifications' , request ) . done ( doneQuery ) . fail ( failQuery ) ; } function doneQuery ( response ) { var isLastQuery = ( response . notifications . length < request . limit ) ; if ( ! isLastQuery ) { request . start_key = response . last_key ; sendQuery ( ) ; } _ ( response . notifications ) . each ( visitor ) ; if ( isLastQuery ) deferred . resolve ( ) ; } function failQuery ( jqHxr , textStatus ) { deferred . reject ( "Error from visitNotifications: " + textStatus ) ; } sendQuery ( ) ; return deferred ; }
Queries the service for a list of notifications for the current user and invokes the given
 callback once for each notification.
Queries the service for a list of notifications for the current user and invokes the given callback once for each notification .
// Dispatches a single query to the server.   // Invokes the callback with the result of a completed query.  If there are  // more results on the server which were paged, creates a continuation function // which will query the next page and returns it. // Send out request for the next page of data, if it exists. // Invoke the visitor on each notification received. // If this was the last page of the query, resolve this method's promise.