-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
39 lines (32 loc) · 942 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
var app = angular
.module('angular-promise-polyfill', [])
.run(['$q', '$window', function($q, $window) {
$window.Promise = function(executor) {
return $q(executor);
};
$window.Promise.all = $q.all.bind($q);
$window.Promise.reject = $q.reject.bind($q);
$window.Promise.resolve = $q.when.bind($q);
$window.Promise.race = function(promises) {
var promiseMgr = $q.defer();
for(var i = 0; i < promises.length; i++) {
promises[i].then(function(result) {
if(promiseMgr) {
promiseMgr.resolve(result);
promiseMgr = null;
}
});
promises[i].catch(function(result) {
if(promiseMgr) {
promiseMgr.reject(result);
promiseMgr = null;
}
});
}
return promiseMgr.promise;
};
}]);
if (typeof module === 'object') {
module.exports = app.name;
}