@@ -33,7 +33,8 @@ function debugModule(module, runtime) {
33 var timestep = Date.now();
33 var timestep = Date.now();
35 if (programPaused) {
35 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
39 runtime.notify(id, v, timestep);
40 runtime.notify(id, v, timestep);
@@ -42,12 +43,13 @@ function debugModule(module, runtime) {
44 function wrapRunDelayed(func, delayMs) {
45 function wrapRunDelayed(func, delayMs) {
45− return safeSetTimeout(func, delayMs);
46+ var cbObj = { func:func, delayMs:delayMs, timerId:0, executed:false };
46− };
47+ var timerId = setTimeout(function() {
47−
48+ cbObj.executed = true;
48− function safeSetTimeout(func, delayMs) {
49+ func();
49− var timerId = setTimeout(func, delayMs);
50+ }, delayMs);
51+ cbObj.timerId = timerId;
50− asyncCallbacks.push({ func:func, delayMs:delayMs, timerId:timerId });
52+ asyncCallbacks.push(cbObj);
51 return timerId;
53 return timerId;
@@ -57,7 +59,9 @@ function debugModule(module, runtime) {
58 function clearAsyncCallbacks() {
60 function clearAsyncCallbacks() {
59 asyncCallbacks.forEach(function(timer) {
61 asyncCallbacks.forEach(function(timer) {
62+ if (!timer.executed) {
60− clearTimeout(timer.timerId);
63+ clearTimeout(timer.timerId);
@@ -75,6 +79,12 @@ function debugModule(module, runtime) {
76 function setPaused(v) {
80 function setPaused(v) {
77 programPaused = v;
81 programPaused = v;
83+ clearAsyncCallbacks();
86+ executeCallbacks(asyncCallbacks);
80 function getPaused() {
90 function getPaused() {
@@ -127,10 +137,18 @@ function debuggerInit(debugModule, runtime) {
127 function restartProgram() {
137 function restartProgram() {
128 resetProgram();
138 resetProgram();
129 debugModule.clearRecordedEvents();
139 debugModule.clearRecordedEvents();
130− debugModule.initialAsyncCallbacks.forEach(function(timer) {
140+ executeCallbacks(debugModule.initialAsyncCallbacks);
131− var func = timer.func;
141+ }
143+ function pauseProgram() {
144+ debugModule.setPaused(true);
147+ function continueProgram() {
148+ if (debugModule.getPaused())
150+ debugModule.setPaused(false);
136 function stepTo(index) {
154 function stepTo(index) {
@@ -179,8 +197,9 @@ function debuggerInit(debugModule, runtime) {
181 var elmDebugger = {
199 var elmDebugger = {
182− reset: resetProgram,
183 restart: restartProgram,
200 restart: restartProgram,
201+ pause: pauseProgram,
202+ kontinue: continueProgram,
184 getMaxSteps: getMaxSteps,
203 getMaxSteps: getMaxSteps,
185 stepTo: stepTo
204 stepTo: stepTo
@@ -286,6 +305,15 @@ function tracePathInit(runtime) {
308+function executeCallbacks(callbacks) {
309+ callbacks.forEach(function(timer) {
310+ if (!timer.executed) {
311+ var func = timer.func;
289function createCanvas() {
317function createCanvas() {
290 var c = document.createElement('canvas');
318 var c = document.createElement('canvas');
291 c.width = window.innerWidth;
319 c.width = window.innerWidth;