diff --git a/speedtest.js b/speedtest.js index b2feca9..d664104 100755 --- a/speedtest.js +++ b/speedtest.js @@ -319,6 +319,11 @@ Speedtest.prototype = { */ start: function() { if (this._state == 3) throw "Test already running"; + // Terminate any existing worker from previous test + if (this.worker) { + this.worker.terminate(); + this.worker = null; + } this.worker = new Worker("speedtest_worker.js?r=" + Math.random()); this.worker.onmessage = function(e) { if (e.data === this._prevData) return; @@ -337,6 +342,11 @@ Speedtest.prototype = { } catch (e) { console.error("Speedtest onend event threw exception: " + e); } + // Terminate worker after test completes + if (this.worker) { + this.worker.terminate(); + this.worker = null; + } } }.bind(this); this.updater = setInterval( diff --git a/test_multiple_instances.html b/test_multiple_instances.html new file mode 100644 index 0000000..4254b27 --- /dev/null +++ b/test_multiple_instances.html @@ -0,0 +1,166 @@ + + + +
+This page tests running multiple Speedtest instances sequentially and simultaneously.
+ +