How can I set a Deffered from resolved back to the initial state?
I tried creating a new Queue, but in that case I will lose all events I have added so far, If I don’t resolve it first.
Is there maybe a state model of the Deferred (Processing –> Resolved… maybe something in between, how you can get from Resolved into Processing….)
This is what I have so far:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<script src="jquery-1.8.3.min.js"></script>
<script>
var deferredReady = jQuery.Deferred();
$(function () {
$('#Queue1, #Queue2').click(function () {
var text = $(this).text();
deferredReady.done(function () {
$('<p>', {
text: text
}).appendTo('body');
});
});
$('#QueueReady').click(function () {
deferredReady.resolve();
});
$('#NewQueue').click(function () {
// deletes the old queue (resolve it first)
deferredReady = jQuery.Deferred();
});
});
</script>
</head>
<body>
<button id="Queue1">Add Comamnd to ready Queue</button>
<button id="Queue2">Add otherComamnd to ready Queue</button>
<button id="QueueReady">Set Queue to ready</button>
<button id="NewQueue">Set Queue to ready</button>
</body>
</html>
No, this conctraticts the original intent of deferred objects. As soon as a
Deferredis resolved or rejected, previously specified callbacks are called and the Deferred changes irrevocably from its initial “pending” state to either “resolved” or “rejected”. What would you expect from setting it back to the initial state? If you want to add a new handler to a deferred object which may or may not be already resolved, this is not a problem. The handler will be called immediately: