MCPcopy Index your code
hub / github.com/angular-ui/ui-router / qFactory

Function qFactory

test/angular/1.7/angular.js:17876–18266  ·  view source on GitHub ↗

* Constructs a promise manager. * * @param {function(function)} nextTick Function for executing functions in the next turn. * @param {function(...*)} exceptionHandler Function into which unexpected exceptions are passed for * debugging purposes. * @param {boolean=} errorOnUnhandledRejection

(nextTick, exceptionHandler, errorOnUnhandledRejections)

Source from the content-addressed store, hash-verified

17874 * @returns {object} Promise manager.
17875 */
17876function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
17877 var $qMinErr = minErr('$q', TypeError);
17878 var queueSize = 0;
17879 var checkQueue = [];
17880
17881 /**
17882 * @ngdoc method
17883 * @name ng.$q#defer
17884 * @kind function
17885 *
17886 * @description
17887 * Creates a `Deferred` object which represents a task which will finish in the future.
17888 *
17889 * @returns {Deferred} Returns a new instance of deferred.
17890 */
17891 function defer() {
17892 return new Deferred();
17893 }
17894
17895 function Deferred() {
17896 var promise = this.promise = new Promise();
17897 //Non prototype methods necessary to support unbound execution :/
17898 this.resolve = function(val) { resolvePromise(promise, val); };
17899 this.reject = function(reason) { rejectPromise(promise, reason); };
17900 this.notify = function(progress) { notifyPromise(promise, progress); };
17901 }
17902
17903
17904 function Promise() {
17905 this.$$state = { status: 0 };
17906 }
17907
17908 extend(Promise.prototype, {
17909 then: function(onFulfilled, onRejected, progressBack) {
17910 if (isUndefined(onFulfilled) && isUndefined(onRejected) && isUndefined(progressBack)) {
17911 return this;
17912 }
17913 var result = new Promise();
17914
17915 this.$$state.pending = this.$$state.pending || [];
17916 this.$$state.pending.push([result, onFulfilled, onRejected, progressBack]);
17917 if (this.$$state.status > 0) scheduleProcessQueue(this.$$state);
17918
17919 return result;
17920 },
17921
17922 'catch': function(callback) {
17923 return this.then(null, callback);
17924 },
17925
17926 'finally': function(callback, progressBack) {
17927 return this.then(function(value) {
17928 return handleCallback(value, resolve, callback);
17929 }, function(error) {
17930 return handleCallback(error, reject, callback);
17931 }, progressBack);
17932 }
17933 });

Callers 2

$QProviderFunction · 0.70
$$QProviderFunction · 0.70

Calls 5

minErrFunction · 0.70
extendFunction · 0.70
isUndefinedFunction · 0.70
scheduleProcessQueueFunction · 0.70
handleCallbackFunction · 0.70

Tested by

no test coverage detected