mirror of
https://github.com/jquery/jquery.git
synced 2026-02-01 21:45:03 -05:00
Deferred: Make jQuery.when synchronous when possible
Closes gh-3102 Fixes gh-3100 Closes gh-3105
This commit is contained in:
@@ -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();
|
||||
}
|
||||
} );
|
||||
|
||||
Reference in New Issue
Block a user