Created
July 24, 2016 05:54
-
-
Save danielt69/de8b89b77e885d9c49e112e86d856f7c to your computer and use it in GitHub Desktop.
Wrap setTimeout in a Deferred
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.wait = function(delay, context){ | |
| var deferred = $.Deferred(); | |
| var timer = setTimeout(function(){ | |
| deferred.resolveWith(context || deferred); | |
| }, delay); | |
| deferred.fail(function(){ | |
| clearTimeout(timer); | |
| }); | |
| return deferred; | |
| }; | |
| // how to use: | |
| $.wait(1250).then(function(){ | |
| // your code goes here | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment