diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2016-05-04 15:30:24 -0400 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2016-05-09 12:14:22 -0400 |
commit | de71e9755fc0b5d45ee3fa1bac5481c2466dad6e (patch) | |
tree | e417c398310472e91e47af8cb9cbe0f11ccdf887 /src | |
parent | e8825a529b97a27b8b2e40eaaa7773189642c772 (diff) | |
download | jquery-de71e9755fc0b5d45ee3fa1bac5481c2466dad6e.tar.gz jquery-de71e9755fc0b5d45ee3fa1bac5481c2466dad6e.zip |
Deferred: Make jQuery.when synchronous when possible
Closes gh-3102
Fixes gh-3100
Closes gh-3105
Diffstat (limited to 'src')
-rw-r--r-- | src/deferred.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/deferred.js b/src/deferred.js index 6e4d43b31..73b2f9ef2 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -366,16 +366,21 @@ jQuery.extend( { // Single- and empty arguments are adopted like Promise.resolve if ( remaining <= 1 ) { - adoptValue( singleValue, master.resolve, master.reject ); + adoptValue( singleValue, master.done( updateFunc( i ) ).resolve, master.reject ); // Use .then() to unwrap secondary thenables (cf. gh-3000) - return master.then(); + if ( master.state() === "pending" || + jQuery.isFunction( resolveValues[ i ] && resolveValues[ i ].then ) ) { + + return master.then(); + } } // Multiple arguments are aggregated like Promise.all array elements while ( i-- ) { adoptValue( resolveValues[ i ], updateFunc( i ), master.reject ); } + return master.promise(); } } ); |