Delivers all the emails on the queue.

@return {promise} An promise object
777289
function(){
			var payload = { recipients: {} },
				invalid = [],
				promise = new Promise();
			for(var i=0, j=this.mails.length; i < j; i++){
				var data = this.mails[i],
					email = data.email;

					if(!data.template_id){
						invalid.push(data)
						data.error = "No template provided"
						continue;
					}

					if(typeof data.email === 'undefined'){
						invalid.push(data)
						data.error = "No email provided"
						continue;
					}


				delete data['email'];

				payload.recipients[email] = data
			}
			if(invalid.length > 0){
				promise.reject('invalid', invalid);
			}else{
				apostle.send(payload, promise);
			}
			return promise;
		}
722977
function(){
        var deferred = Q.defer();

        fs.readFile( this.path, "utf-8", function( err, data ){
            if( err ){
                deferred.resolve( err );
                return;
            }

            this.parentTemplateId = utils.detectTemplateId( data );
            this.defaultValues = this.pickOutDefaultValues( data );
            this.processor = _.template( this.convertToTemplateFormat( data ) );

            deferred.resolve( this );
        }.bind( this ) );

        return deferred.promise;
    }
1255624
function() {

        /* Find all modules to import */
        var server = this;
        return utils.resolve(arguments).then(function(modules) {

          /* Prune modules already injected in the worker */
          var injectables = [];
          for (var moduleName in modules) {
            if (injectedModules[moduleName]) continue;
            injectables.push(modules[moduleName]);
          }

          /* Inject each module in the worker */
          var promises = [];
          for (var i in injectables) {

            /* Message id, deferred, and (derived) promise */
            promises.push(server.send({module: injectables[i]})
              .then(function(moduleName) {
                injectedModules[moduleName] = true;
                return moduleName;
              })
            );
          }

          /* Return a promise combining all imports */
          return Promise.all(promises);
        });
      }
1229251
function queue ({
  load,
  retry = 0

}) {

  const emitter = new EventEmitter()
  emitter.setMaxListeners(0)

  const results = {}

  function add (param = '', callback) {
    let key

    if (arguments.length === 1) {
      callback = param
      key = ''

    } else {
      key = JSON.stringify(param)
    }

    if (key in results) {
      return callback(...results[key])
    }

    emitter.on(key, callback)

    if (emitter.listenerCount(key) === 1) {
      loadResource(param, load, retry)
      .then((data) => {
        results[key] = [null, data]
        emitter.emit(key, null, data)
        emitter.removeAllListeners(key)
      })
      .catch((err) => {
        emitter.emit(key, err)
        // again
        emitter.removeAllListeners(key)
      })
    }
  }

  return {
    // expose cache so that we could handle it
    cache: results,
    add: (param) => {
      return new Promise((resolve, reject) => {
        add(param, (err, data) => {
          if (err) {
            return reject(err)
          }

          resolve(data)
        })
      })
    }
  }
}
652424
function () {
                    if (this._lastGroup && typeof this._lastGroup.index === "number") {
                        return Promise.wrap(this._count);
                    } else {
                        // Even if there's a current estimate for _count, consider this call to be a request to determine the true
                        // count.

                        var that = this;
                        var countPromise = new Promise(function (complete) {
                            var fetch = {
                                initialBatch: function () {
                                    that._fetchNextIndex();
                                },
                                getGroup: function () { return null; },
                                countBefore: 0,
                                countAfter: 0,
                                complete: function (failed) {
                                    if (failed) {
                                        that._count = 0;
                                    }

                                    var count = that._count;
                                    if (typeof count === "number") {
                                        complete(count);
                                        return true;
                                    } else {
                                        return false;
                                    }
                                }
                            };

                            that._fetchQueue.push(fetch);

                            if (!that._itemBatch) {
                                that._continueFetch(fetch);
                            }
                        });

                        return (typeof this._count === "number" ? Promise.wrap(this._count) : countPromise);
                    }
                }
753270
function mail() {
  var awsURL = !!CONFIG && !!CONFIG.aws && !!CONFIG.aws.url ? CONFIG.aws.url : false;

  if (EMAIL) {
    CONFIG.mail.to = [EMAIL];
  }

  return gulp.src('dist/**/*.html')
    .pipe($.if(!!awsURL, $.replace(/=('|")(\/?assets\/img)/g, "=$1"+ awsURL)))
    .pipe($.mail(CONFIG.mail))
    .pipe(gulp.dest('dist'));
}
488432
def deliver(template, from, to, vars={}, opts={})
      @info = vars
      @info[:company] = from[:name]

      mail(
        from: format_sender(from),
        to: to[:email],
        subject: humanize(template),
        template_path: 'system_notifications',
        template_name: template
      )
    end
180198
function() {
    var collection = [];
    for (let id of this.store._keys) {
      if (id.startsWith("unprocessed")) {
        collection.push(this.get(id));
      }
    }
    return Promise.resolve(collection);
  }
1274558
function() {
    return new Promise((resolve, reject) => {
      let instance;
      if (this.modelElement.name === this.node.getName()) {
        instance = this.node;
      } else {
        instance = this.mapper.getObject(this.modelElement.path());
      }

      if (instance) {
        if (instance.isStarted()) {
          instance.__update__(timesUp('update(...)', 30000, (err) => {
            if (err) {
              this.log.error('Unable to update ' + instance.getPath());
              reject(err);
            } else {
              this.log.debug(instance.getPath());
              this.node.kCore.emitter.emit('instanceUpdated', instance);
              resolve();
            }
          }));
        }
      } else {
        reject(new Error(this.toString() + ' error: unable to update instance ' + this.modelElement.name));
      }
    });
  }
397089
function exec() {
    var defer = q.defer();
    cp.exec(this, function(err, stdout, stderr) {
        if (err) console.log('exec err: '+ err);
        console.log(stdout);
        defer.resolve(err)
    })
    return defer.promise;
}
707758
function() {
      if (this.subscriptions.length) {
        return Promise.map(this.subscriptions, (op) => {
          return op();
        })
        .then(() => {
          log.info(`Restarted ${this.subscriptions.length} subscriptions`);
        });
      }
      return Promise.resolve();
    }
572336
function chunks() {
  for (var
    update,
    out = [],
    updates = this.updates,
    template = this.chunks,
    callback = this.callback,
    all = Promise.resolve(template[0]),
    chain = function (after) {
      return all.then(function (through) {
                  notify(through);
                  return after;
                });
    },
    getSubValue = function (value) {
      if (isArray(value)) {
        value.forEach(getSubValue);
      } else {
        all = chain(
          Promise.resolve(value)
                 .then(resolveArray)
        );
      }
    },
    getValue = function (value) {
      if (isArray(value)) {
        var hc = Promise.resolve(createHyperComment());
        all = chain(hc);
        value.forEach(getSubValue);
        all = chain(hc);
      } else {
        all = chain(
          Promise.resolve(value)
                 .then(resolveAsTemplateValue(update))
                 .then(update === asTemplateValue ? identity : update)
        );
      }
    },
    notify = function (chunk) {
      out.push(chunk);
      callback(chunk);
    },
    i = 1,
    length = arguments.length; i < length; i++
  ) {
    update = updates[i - 1];
    getValue(arguments[i]);
    all = chain(template[i]);
  }
  return all.then(notify).then(function () { return out; });
}
89066
function() {
	var deferred = q.defer();
	setTimeout(function() {
		console.log("Async Action 1 Completed");
		deferred.resolve();
	}, 1000);
	return deferred.promise;
}
499519
function fetchOrders() {
    return new Promise((resolve, reject) => {
        https.get('https://services.odata.org/V4/Northwind/Northwind.svc/Orders',
        (result) => {
            var str = '';
            result.on('data', (b) => str += b);
            result.on('error', reject);
            result.on('end', () => resolve(JSON.parse(str).value));
        });
    })
}
931829
function() {
    var deferred = $q.defer();

    var current = $state.current();

    // Evaluate
    if(current) {
      var sources = (typeof current.load === 'string' ? [current.load] : current.load) || [];
      
      // Get promises
      $q.all(sources
        .map(function(src) {
          return _createLoadable(src);
        })
        .filter(function(loadable) {
          return !loadable.isComplete;
        })
        .map(function(loadable) {
          return loadable.promise;
        })
      )
          .then(function() {
            deferred.resolve();

          }, function(err) {
            $rootScope.$broadcast('$loadableError', err);
            deferred.reject(err);
          });

    // No state
    } else {
      deferred.resolve();
    }

    return deferred.promise;
  }
818749
function() {
            if ($cachedPromise) {
                return $cachedPromise;
            }

            var $promise = ajax.fetch(this.getURL(), Crocodoc.ASSET_REQUEST_RETRIES);

            // @NOTE: promise.then() creates a new promise, which does not copy
            // custom properties, so we need to create a futher promise and add
            // an object with the abort method as the new target
            $cachedPromise = $promise.then(processStylesheetContent).promise({
                abort: function () {
                    $promise.abort();
                    $cachedPromise = null;
                }
            });
            return $cachedPromise;
        }
853786
function populate(_records, _params) {
    var promises = [];
    for(var i = 0; i < _records.length; i++) {
      promises.push(_records[i].$resolve(_params).$asPromise());
    }
    return $q.all(promises);
  }