/*
haveResults is the callback for the request module. Called when the API call is
resolved.
557056
function haveResults(err, response, body) {
    var jsn;
    if (err) {
      callback(err);
      return;
    }
    //fs.writeFileSync('response.txt', JSON.stringify(response, null, '  '), 'utf8');
    if (response && response.statusCode !== 200) {
      callback('Resp Status: ' + response.statusCode);
      return;
    }
    try {
      jsn = JSON.parse(body);
    } catch(e) {
      callback('JSON Parse error:\n' + body);
      return;
    }
    if (!jsn.status || jsn.status !== 200) {
      callback('Status: ' + (jsn.status ? String(jsn.status) : '555') + ' ' + (jsn.message ? jsn.message : ''));
      return;
    }
    jsn.resultSetFiltered = jsn.resultSet.filter(function(itm) {
      return filter.indexOf(itm.tID) === -1;
    });
    callback(null, jsn, fname); // DONE - return results to caller
  }
115451
function getResults(result, objects) {
		
		// if there are no results, resolve an empty array
		if (!result) {
			return new Promise(function(resolve, reject) {
				resolve([]);
			});
		}
		
		// if the result object is undefined or not an array, make it one
		result.objects = result.objects || [];
		result.objects = Array.isArray(result.objects) ? result.objects : [result.objects];
		objects        = _.union(objects, result.objects);
		
		// if the result has a token, there are more results, continue to get them
		if (result.token) {
			return _client.method('ContinueRetrievePropertiesEx', {
				_this: _client._sc.propertyCollector,
				token: result.token
			})
			.then(function(results) {
				return getResults(results, objects);
			});
		}
		
		// if there are no more results, return the formatted results
		else {
			return new Promise(function(resolve, reject) {
				resolve(env.format(objects));
			});
		}
	}
454518
function ReturnResult(result) {
  if (errors.length) {
    result.errors = errors;
  }
  var state = data.state;
  if (state) {
    var AMS = MathJax.Extension["TeX/AMSmath"];
    var GLYPH = (MathJax.OutputJax.SVG||{}).BBOX.GLYPH;
    state.AMS.startNumber = AMS.startNumber;
    state.AMS.labels = AMS.labels;
    state.AMS.IDs = AMS.IDs;
    state.mmlID = MathJax.ElementJax.mml.SUPER.ID;
    state.glyphs = GLYPH.glyphs;
    state.defs = GLYPH.defs;
    state.n = GLYPH.n;
    state.ID = ID;
  }
  serverState = STATE.READY;
  callback(result, originalData);
  if (serverState === STATE.READY) StartQueue();
}
614647
function resultRaw (results) {
    // throw error if results required and not retrieved
    if (this.args.required && !results.length) {
        // throw error
        throw this.error('no records found')
    }
    // if only ids were selected the return result object to fetch records
    if (this.select.isSelectOnlyIds) {
        // build result object
        var result = new ImmutableCoreModelResult({
            query: this,
            results: results,
        })
        // return result or all records if specified
        return this.args.all ? result.all() : result
    }
    // otherwise return ImmutableCoreModelInstance record(s)
    else {
        // query is for a single record
        if (this.args.limit === 1) {
            // return new instance or undefined
            return results.length
                ? this.newInstance(results[0])
                : undefined
        }
        // query is for multiple records
        else {
            return _.map(results, result => this.newInstance(result))
        }
    }
}
941416
function handleListResults( results ) {
		grunt.verbose.writeln( 'BowerMap::handleListResults' );

		for ( var k in results ) {
			if ( results.hasOwnProperty( k ) ) {
				grunt.verbose.writeln( '------------------------------------' );
				grunt.verbose.writeln( '    ' + k + ' - ' + results[k] );
				if ( ignore.indexOf( k ) >= 0 ){
					grunt.verbose.writeln( '    ' + k + ' - IGNORED' );
				}
				else{
					copyComponentFiles( k, results[k] );
				}
			}
		}
		done();
	}
1058084
function() {
        var _status = STATUS_PENDING;
        var _args;
        var _callbacks = {
            success: [],
            fail: [],
            done: []
        };

        function _registerCallback(resultType, callback) {
            if (typeof callback !== 'function') {
                //Invalid input args. Throw an error.
                throw 'Invalid argument: callback. Must be a function.';
            }

            if (_status !== STATUS_PENDING) {
                if (_status === resultType || resultType === RESULT_TYPE_DONE) {
                    // Promise has already been satisfied. Just invoke the
                    // callback.
                    callback.apply(null, _args);
                }
            } else {
                // Promise has not yet been satisfied. Remember it, and
                // invoke when ready.
                _callbacks[resultType].push(callback);
            }
        }

        function _satisfy(resultType, args) {
            if (_status !== STATUS_PENDING) {
                return;
            }
            _args = args;
            _status = resultType;

            function doCallback(item, index) {
                item.apply(null, _args);
            }

            //Trigger any callbacks that have been queued.
            _callbacks[resultType].forEach(doCallback);
            _callbacks.done.forEach(doCallback);

            //Clear out any callback references.
            _callbacks.succes = [];
            _callbacks.fail = [];
            _callbacks.done = [];
        }

        var _promise = {
            /*
             * Invoked to allow callers to register callbacks that will be
             * triggered on completion of the deferred activity. This callback
             * will be triggered whether or not the completion was successful.
             */
            done: function(callback) {
                _registerCallback(RESULT_TYPE_DONE, callback);
                return (_promise);
            },

            /*
             * Invoked to allow callers to register callbacks that will be
             * triggered on successful completion of the deferred activity.
             */
            success: function(callback) {
                _registerCallback(STATUS_SUCCESS, callback);
                return (_promise);
            },

            /*
             * Invoked to allow callers to register callbacks that will be
             * triggered on unsuccessful completion of the deferred activity.
             */
            fail: function(callback) {
                _registerCallback(STATUS_FAIL, callback);
                return (_promise);
            },

            /* 
             * Returns the results returned by the deferred activity.
             */
            results: function() {
                return _args;
            }
        }

        var deferredObject = {
            /*
             * Allows a callback to be registered that will be called once the
             * deferred has been resolved or rejected.
             */
            done: _promise.done,

            /*
             * Allows a callback to be registered that will be called once the
             * deferred has been resolved.
             */
            success: _promise.success,

            /*
             * Allows a callback to be registered that will be called once the
             * deferred has been rejected.
             */
            fail: _promise.fail,

            /*
             * Fulfills the promise by resolving it.
             */
            resolve: function() {
                _satisfy(STATUS_SUCCESS, Array.prototype.slice.call(arguments, 0));
            },

            /*
             * Fulfills the promise by rejecting it.
             */
            reject: function() {
                _satisfy(STATUS_FAIL, Array.prototype.slice.call(arguments, 0));
            },

            /*
             * Gets a promise associated with the deferred object.
             */
            promise: function() {
                return Object.create(_promise);
            },

            /*
             * Generates a callback that resolves/rejects the deferred object
             * based on the success/failure of an operation, determined by the
             * first argument in.
             */
            getResolver: function() {
                var ctxArgs = Array.prototype.slice.call(arguments, 0);
                return function(err, data) {
                    if (!err) {
                        var args = Array.prototype.slice.call(arguments, 1);
                        deferredObject.resolve.apply(null,
                            ctxArgs.concat(args));
                    } else {
                        deferredObject.reject.apply(null,
                            ctxArgs.concat([err]));
                    }
                };
            },

            /*
             * Generates a callback that resolves/rejects the deferred after a
             * specified number of steps have been completed, indicated by the
             * invocation of stepComplete().
             */
            getMultiStepResolver: function(count) {
                var _count = count;
                var ctxArgs = Array.prototype.slice.call(arguments, 1);

                // If the step count is zero, resolve immediately.
                if (_count === 0) {
                    deferredObject.resolve.apply(null, ctxArgs);
                }

                return {
                    /*
                     * Indicates that a specific step was completed. The
                     * promise will be treated as resolved if this method
                     * is invoked a given number of times.
                     */
                    stepComplete: function() {
                        var ca
                        _count--;
                        if (_count === 0) {
                            var args = Array.prototype.slice.call(arguments, 0);
                            deferredObject.resolve.apply(null,
                                ctxArgs.concat(args));
                        }
                    },

                    /*
                     * Rejects the deferred object without waiting for any
                     * further processing.
                     */
                    reject: function() {
                        var args = Array.prototype.slice.call(arguments, 0);
                        deferredObject.reject.apply(null, ctxArgs.concat(args));
                    }
                }
            }
        };

        return deferredObject;
    }
1246036
function fetchResults(searchText) {
      var items = $scope.$parent.$eval(self.remoteMethod),
        isList = angular.isArray(items),
        isPromise = items ? !!items.then : false; // Every promise should contain a `then` property

      if (isList) onResultsRetrieved(items);
      else if (isPromise) handleAsyncResults(items);

      function handleAsyncResults(items) {
        if (!items) return;

        items = $q.when(items);
        setLoading(true);
        items.then(onResultsRetrieved);
      }

      function onResultsRetrieved(matches) {

        // Just cache the results if the request is now outdated.
        // The request becomes outdated, when the new searchText has changed during the result fetching.
        if ((searchText || '') !== (self.searchText || '')) {
          return;
        }

        handleResults(matches);
      }
    }
306964
function cacheResults (results) {
    // get current max record number
    return this.cache.model.maxRecordNumber({
        session: this.query.session,
    }).then(n => {
        // if state has changed do not cache
        if (n !== this.initialMaxRecordNumber) {
            return
        }
        // JSON encode data to cache
        try {
            var cacheValue = JSON.stringify({
                n: n,
                v: results,
            })
        }
        catch (err) {
            // ignore errors
        }
        // cache result
        if (cacheValue) {
            debug('view:select:collection:set', this.selectCacheKey)
            return this.cache.redis.setAsync(this.selectCacheKey, cacheValue)
        }
    })
}
831887
function showResults () {
  var results = editors.results;

  setTimeout(function () {
    results[0].scrollIntoView();
    results.addClass("animated")
      .one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function () {
        // Remove the "animated" class when the animation ends,
        // so we can replay the animation again next time
        results.removeClass("animated");
      });
  });
}
1020269
protected function handleS3PromisesResult($s3_results)
    {
        foreach ($s3_results as $promise) {
            if ($promise['state'] !== 'fulfilled') {
                $code = HttpStatusCodes::HTTP_SERVICE_UNAVAILABLE;
                if (array_key_exists('value', $promise)) {
                    $response = $promise['value'];
                    $code = $response->getStatusCode();
                }
                throw new FilestackException("Errored uploading to s3", $code);
            }
        }
    }
507717
function(results) {
			// Only do so if `callback` is specified
			if (IODOpts.callback) {
				var options = { url: IODOpts.callback.uri }
				var res = JSON.stringify(results)

				// Url-encode use `form` property
				if (IODOpts.callback.method === 'encoded') {
					options.form = { results: res }
				}

				var r = request.post(options, function(err, res) {
					// Emits `CbError` if any error occurs while sending results to callback
					if (err) IOD.eventEmitter.emit('CbError', err)
					else if (res.statusCode !== 200) {
						IOD.eventEmitter.emit('CbError', 'Status Code: ' + res.statusCode)
					}
				})

				// Multipart use form object
				if (IODOpts.callback.method === 'multipart') {
					var form = r.form()
					form.append('results', res)

					form.on('error', function(err) {
						IOD.evenEmitter.emit('CBError', err)
					})
				}
			}
		}
145200
function PageResult(items, totalCount, requestOffset, requestCount, baseUrl) {
      this.items = items != null ? items : [];
      this.totalCount = totalCount != null ? totalCount : 0;
      this.requestOffset = requestOffset != null ? requestOffset : 0;
      this.requestCount = requestCount != null ? requestCount : 25;
      this.baseUrl = baseUrl != null ? baseUrl : null;
      this.toRest = __bind(this.toRest, this);

      this.directButtons = __bind(this.directButtons, this);

      this.createButton = __bind(this.createButton, this);

      this.prevButton = __bind(this.prevButton, this);

      this.nextButton = __bind(this.nextButton, this);

      this.prevButtonEnabled = __bind(this.prevButtonEnabled, this);

      this.nextButtonEnabled = __bind(this.nextButtonEnabled, this);

      this.currentPageAsString = __bind(this.currentPageAsString, this);

      this.pageToString = __bind(this.pageToString, this);

      this.numberOfPages = __bind(this.numberOfPages, this);

      this.lastPage = __bind(this.lastPage, this);

      this.firstPage = __bind(this.firstPage, this);

      this.currentPage = __bind(this.currentPage, this);

    }
145696
function _handleResult(callback, err, res) {
    return callback(null, {
        error:  err,
        result: res
    });
}
787781
def _succeed(self, result):
        

        for fn, args, kwargs in self._callbacks:
            fn(result, *args, **kwargs)
        self._resulted_in = result
986192
function addResults(transport, next) {
        queryTransport(transport, function (err, result) {
            //
            // queryTransport could potentially invoke the callback
            // multiple times since Transport code can be unpredictable.
            //
            if (next) {
                result = err || result;
                if (result) {
                    results[transport.name] = result;
                }

                next();
            }

            next = null;
        });
    }
554449
function executeRelatedResultResolve (result) {
    // skip if resolve not specified
    if (!this.args.resolve) {
        return
    }
    // create new resolve instance
    var resolve = new ImmutableCoreModelResolve({
        query: this,
        result: result,
    })
    // exceute resolve
    return resolve.resolve()
}
106071
function doResolve(result) {
  let self = this;
  if (result === self) {
    // Promise Standard 2.3.1
    return doReject.call(
      self,
      new TypeError("Can not resolve 'Promise' itself")
    );
  }
  // Promise Standard 2.3.3.2
  try {
    // Promise Standard 2.3.2 and 2.3.3 can be merge
    // if result is a thenable(.then)
    let then = safelyToThen(result);
    if (then) {
      // Promise Standard 2.3.3.3
      safelyToExecutor(self, then.bind(result));
    } else {
      // [[ async ]]
      setTimeout(function() {
        // commonly case
        if (self.currentState === Shared.PENDING) {
          self.currentState = Shared.FULFILLED;
          self.valOrErr = result;
          for (let i = 0; i < self.onFulfilledCallback.length; i++) {
            self.onFulfilledCallback[i](result);
          }
          self.onFulfilledCallback = [];
        }
      }, 0);
    }
    // case: when then(doResolve, doReject) -> asyncToResolveOrReject -> func(arg) -> return self
    return self;
  } catch (error) {
    return doReject.call(self, error);
  }
}