Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
I use the multithread HTML5 worker which will be able to abort an synchronous XMLHttpRequest pointing to an unresponsive URL. This does not block the browser.
function sleep(milliseconds) {
var xhr = new XMLHttpRequest();
// Open a non existing url
xhr.open('GET', location.protocol + '//sleep' + (new Date()).getTime(), false);
var blob = new Blob([
"onmessage = function() { setTimeout(function() {postMessage('done');}, "+milliseconds+"); }"]);
var blobURL = window.URL.createObjectURL(blob);
var worker = new Worker(blobURL);
worker.onmessage = function() {
xhr.abort();
window.URL.revokeObjectURL(blobURL);
};
worker.postMessage('sleep');
xhr.send(null);
};
var start = new Date().getTime();
sleep(2000);
var end = new Date().getTime();
console.log('time: ' + (end - start));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.