Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
$.wait jQuery extension that wraps setTimeout in a $.Deferred object
JavaScript
Tree: 097a03d44f

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
README.md
jquery.wait.js

README.md

jquery-wait

$.wait jQuery extension that wraps setTimeout in a Deferred object.

Basic example:

$.wait(500).then(function(){
  console.log('A half-second later.');
});

This is similar to _.delay, except that you can cancel the done callbacks by calling .reject() on the returned Deferred object:

var deferred = $.wait(5000).done(function(){
  console.log('This won\'t run if the deferred object is rejected within 5 seconds.');
});

if (confirm('Should we cancel the queued action?')) {
  deferred.reject();
}

Use it along side the Promise-enhanced jqXHR object returned from $.ajax:

var jqXHR = $.ajax({
  // ajax options here
});

$.when(jqXHR, $.wait(500)).done(function(){
  console.log('This won\'t run until the AJAX has returned and at least 500 ms have passed.');
});

Use $.when to know when all Deferred objects have been completed.

Something went wrong with that request. Please try again.