Given the code using Promise
constructor
let promise = () => new Promise(resolve => resolve(1));
new Promise((resolve, reject) => {
setTimeout(() => reject("10 seconds exceeded"), 10000);
resolve(promise())
})
.then(data => console.log(data))
.catch(err => console.error(err));
1
is logged at console
Given the equivalent code using jQuery.Deferred the jQuery.deferred
object is logged at .then()
, not the value passed to jQuery.deferred.resolve
let promise = () => new $.Deferred(dfd => dfd.resolve(1));
new $.Deferred(dfd => {
setTimeout(() => dfd.reject("10 seconds exceeded"), 10000);
dfd.resolve(promise());
})
.then(data => console.log(data))
.fail(err => console.error(err));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
though passing jQuery.deferred
promise object to .then()
does return expected result
let promise = () => new $.Deferred(dfd => dfd.resolve(1));
new $.Deferred(dfd => {
setTimeout(() => dfd.reject("10 seconds exceeded"), 10000);
promise().then(data => dfd.resolve(data));
})
.then(data => console.log(data))
.fail(err => console.error(err));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
Is the output a jQuery bug relevant to jQuery's implementation of Promise
and the specification?