Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove code relating to parallel execution from PeriodicalExecuter. #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 9 additions & 22 deletions src/prototype/lang/periodical_executer.js
Expand Up @@ -31,13 +31,18 @@ var PeriodicalExecuter = Class.create({
initialize: function(callback, frequency) { initialize: function(callback, frequency) {
this.callback = callback; this.callback = callback;
this.frequency = frequency; this.frequency = frequency;
this.currentlyExecuting = false;


this.registerCallback(); this.start();
}, },


registerCallback: function() { /**
this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000); * PeriodicalExecuter#start() -> undefined
*
* Starts the [[PeriodicalExecuter]] or restarts it if `#stop`
* was previously called.
**/
start: function() {
if (!this.timer) this.timer = setInterval(this.execute.bind(this), this.frequency * 1000);
}, },


execute: function() { execute: function() {
Expand Down Expand Up @@ -71,22 +76,4 @@ var PeriodicalExecuter = Class.create({
clearInterval(this.timer); clearInterval(this.timer);
this.timer = null; this.timer = null;
}, },

onTimerEvent: function() {
if (!this.currentlyExecuting) {
// IE doesn't support `finally` statements unless all errors are caught.
// We mimic the behaviour of `finally` statements by duplicating code
// that would belong in it. First at the bottom of the `try` statement
// (for errorless cases). Secondly, inside a `catch` statement which
// rethrows any caught errors.
try {
this.currentlyExecuting = true;
this.execute();
this.currentlyExecuting = false;
} catch(e) {
this.currentlyExecuting = false;
throw e;
}
}
}
}); });
20 changes: 0 additions & 20 deletions test/unit/periodical_executer_test.js
Expand Up @@ -12,24 +12,4 @@ new Test.Unit.Runner({
this.assertEqual(3, peEventCount); this.assertEqual(3, peEventCount);
}); });
}, },

testOnTimerEventMethod: function() {
var testcase = this,
pe = {
onTimerEvent: PeriodicalExecuter.prototype.onTimerEvent,
execute: function() {
testcase.assert(pe.currentlyExecuting);
}
};

pe.onTimerEvent();
this.assert(!pe.currentlyExecuting);

pe.execute = function() {
testcase.assert(pe.currentlyExecuting);
throw new Error()
}
this.assertRaise('Error', pe.onTimerEvent.bind(pe));
this.assert(!pe.currentlyExecuting);
}
}); });