Skip to content

Instantly share code, notes, and snippets.

@jbpros
Forked from Slicertje/gist:1322603
Created October 28, 2011 17:00
Show Gist options
  • Save jbpros/1322767 to your computer and use it in GitHub Desktop.
Save jbpros/1322767 to your computer and use it in GitHub Desktop.
Detect if callback is called
function doTest (callback) {
var isCallbackCalled = false;
var successCallback = function () {
isCallbackCalled = true;
};
callback.apply(null, [ successCallback ]);
if (isCallbackCalled) {
alert('Callback called');
}
else {
alert('Callback not called');
}
}
doTest(function (callback) {
alert('Test 1, callback called!');
setTimeout(callback, 100);
});
doTest(function(callback) {
alert('Test 2, callback not called');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment