@@ -33,7 +33,8 @@ function debugModule(module, runtime) {
3333 var timestep = Date.now();
3434
3535 if (programPaused) {
36− // ignore notify because we are stepping
36+ // ignore async events generated while playing back
37+ // or user events while program is paused
3738 }
3839 else {
3940 runtime.notify(id, v, timestep);
@@ -42,12 +43,13 @@ function debugModule(module, runtime) {
4243 };
4344
4445 function wrapRunDelayed(func, delayMs) {
45− return safeSetTimeout(func, delayMs);
46− };
47−
48− function safeSetTimeout(func, delayMs) {
49− var timerId = setTimeout(func, delayMs);
50− asyncCallbacks.push({ func:func, delayMs:delayMs, timerId:timerId });
46+ var cbObj = { func:func, delayMs:delayMs, timerId:0, executed:false };
47+ var timerId = setTimeout(function() {
48+ cbObj.executed = true;
49+ func();
50+ }, delayMs);
51+ cbObj.timerId = timerId;
52+ asyncCallbacks.push(cbObj);
5153 return timerId;
5254 }
5355
@@ -57,7 +59,9 @@ function debugModule(module, runtime) {
5759
5860 function clearAsyncCallbacks() {
5961 asyncCallbacks.forEach(function(timer) {
60− clearTimeout(timer.timerId);
62+ if (!timer.executed) {
63+ clearTimeout(timer.timerId);
64+ }
6165 });
6266 }
6367
@@ -75,6 +79,12 @@ function debugModule(module, runtime) {
7579
7680 function setPaused(v) {
7781 programPaused = v;
82+ if (programPaused) {
83+ clearAsyncCallbacks();
84+ }
85+ else {
86+ executeCallbacks(asyncCallbacks);
87+ }
7888 }
7989
8090 function getPaused() {
@@ -127,10 +137,18 @@ function debuggerInit(debugModule, runtime) {
127137 function restartProgram() {
128138 resetProgram();
129139 debugModule.clearRecordedEvents();
130− debugModule.initialAsyncCallbacks.forEach(function(timer) {
131− var func = timer.func;
132− func();
133− });
140+ executeCallbacks(debugModule.initialAsyncCallbacks);
141+ }
142+
143+ function pauseProgram() {
144+ debugModule.setPaused(true);
145+ }
146+
147+ function continueProgram() {
148+ if (debugModule.getPaused())
149+ {
150+ debugModule.setPaused(false);
151+ }
134152 }
135153
136154 function stepTo(index) {
@@ -179,8 +197,9 @@ function debuggerInit(debugModule, runtime) {
179197 }
180198
181199 var elmDebugger = {
182− reset: resetProgram,
183200 restart: restartProgram,
201+ pause: pauseProgram,
202+ kontinue: continueProgram,
184203 getMaxSteps: getMaxSteps,
185204 stepTo: stepTo
186205 };
@@ -286,6 +305,15 @@ function tracePathInit(runtime) {
286305}
287306
288307
308+function executeCallbacks(callbacks) {
309+ callbacks.forEach(function(timer) {
310+ if (!timer.executed) {
311+ var func = timer.func;
312+ func();
313+ }
314+ });
315+}
316+
289317function createCanvas() {
290318 var c = document.createElement('canvas');
291319 c.width = window.innerWidth;