From 4e8b8a64cdac2aace1b6edff54cc0ef1c1946198 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Thu, 15 Mar 2012 13:14:51 -0400 Subject: [PATCH] continuing to push the cps-ing through --- web-world/js-impl.js | 47 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/web-world/js-impl.js b/web-world/js-impl.js index a75cd1a..2663578 100644 --- a/web-world/js-impl.js +++ b/web-world/js-impl.js @@ -1207,40 +1207,37 @@ onCleanRestart = function() { running = false; - stopEventHandlers(); - restart(function(MACHINE) { - MACHINE.params.currentOutputPort = oldOutputPort; - currentBigBangRecord = oldCurrentBigBangRecord; - finalizeClosureCall(MACHINE, world); - }); + stopEventHandlers( + function() { + restart(function(MACHINE) { + MACHINE.params.currentOutputPort = oldOutputPort; + currentBigBangRecord = oldCurrentBigBangRecord; + finalizeClosureCall(MACHINE, world); + }); + }); }; onMessyRestart = function(exn) { running = false; - stopEventHandlers(); - restart(function(MACHINE) { - currentBigBangRecord = oldCurrentBigBangRecord; - MACHINE.params.currentOutputPort = oldOutputPort; - plt.baselib.exceptions.raise(MACHINE, exn); - }); + stopEventHandlers( + function() { + restart(function(MACHINE) { + currentBigBangRecord = oldCurrentBigBangRecord; + MACHINE.params.currentOutputPort = oldOutputPort; + plt.baselib.exceptions.raise(MACHINE, exn); + }); + }); }; startEventHandlers = function(k) { - var i; - for (i = 0; i < eventHandlers.length; i++) { - startEventHandler(eventHandlers[i]); - } - k(); + forEachK(startEventHandler, eventHandlers, k); }; - stopEventHandlers = function() { - var i; - for (i = 0; i < eventHandlers.length; i++) { - stopEventHandler(eventHandlers[i]); - } + stopEventHandlers = function(k) { + forEachK(stopEventHandler, eventHandlers, k); }; - startEventHandler = function(handler) { + startEventHandler = function(handler, k) { var fireEvent = function(who) { if (! running) { return; } var args = [].slice.call(arguments, 1); @@ -1259,10 +1256,12 @@ } }; handler.eventSource.onStart(fireEvent); + k(); }; - stopEventHandler = function(handler) { + stopEventHandler = function(handler, k) { handler.eventSource.onStop(); + k(); };