@@ -243,18 +243,6 @@ function $$QProvider() {
243
243
*/
244
244
function qFactory ( nextTick , exceptionHandler ) {
245
245
var $qMinErr = minErr ( '$q' , TypeError ) ;
246
- function callOnce ( self , resolveFn , rejectFn ) {
247
- var called = false ;
248
- function wrap ( fn ) {
249
- return function ( value ) {
250
- if ( called ) return ;
251
- called = true ;
252
- fn . call ( self , value ) ;
253
- } ;
254
- }
255
-
256
- return [ wrap ( resolveFn ) , wrap ( rejectFn ) ] ;
257
- }
258
246
259
247
/**
260
248
* @ngdoc method
@@ -361,21 +349,26 @@ function qFactory(nextTick, exceptionHandler) {
361
349
} ,
362
350
363
351
$$resolve : function ( val ) {
364
- var then , fns ;
352
+ if ( this . promise . $$state . status > 0 ) return ;
365
353
366
- fns = callOnce ( this , this . $$resolve , this . $$reject ) ;
354
+ if ( isPromiseLike ( val ) ) {
355
+ this . promise . $$state . status = - 1 ;
356
+ this . $$delayResolve ( val ) ;
357
+ } else {
358
+ this . promise . $$state . value = val ;
359
+ this . promise . $$state . status = 1 ;
360
+ scheduleProcessQueue ( this . promise . $$state ) ;
361
+ }
362
+ } ,
363
+
364
+ $$delayResolve : function ( promiseLike ) {
365
+ var that = this ;
366
+ function resolve ( val ) { that . $$resolve ( val ) ; }
367
+ function reject ( val ) { that . $$reject ( val ) ; }
367
368
try {
368
- if ( ( isObject ( val ) || isFunction ( val ) ) ) then = val && val . then ;
369
- if ( isFunction ( then ) ) {
370
- this . promise . $$state . status = - 1 ;
371
- then . call ( val , fns [ 0 ] , fns [ 1 ] , this . notify ) ;
372
- } else {
373
- this . promise . $$state . value = val ;
374
- this . promise . $$state . status = 1 ;
375
- scheduleProcessQueue ( this . promise . $$state ) ;
376
- }
369
+ promiseLike . then ( resolve , reject , this . notify ) ;
377
370
} catch ( e ) {
378
- fns [ 1 ] ( e ) ;
371
+ reject ( e ) ;
379
372
exceptionHandler ( e ) ;
380
373
}
381
374
} ,
@@ -386,6 +379,7 @@ function qFactory(nextTick, exceptionHandler) {
386
379
} ,
387
380
388
381
$$reject : function ( reason ) {
382
+ if ( this . promise . $$state . status > 0 ) return ;
389
383
this . promise . $$state . value = reason ;
390
384
this . promise . $$state . status = 2 ;
391
385
scheduleProcessQueue ( this . promise . $$state ) ;
0 commit comments