Skip to content

Commit

Permalink
Rename timeouts property to timers
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanbeevers committed Nov 13, 2014
1 parent 3713895 commit 1e3d937
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/lolex.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ function addTimer(clock, callback, opt) {
var toId = id++;
var delay = opt.delay || 0;

if (!clock.timeouts) {
clock.timeouts = {};
if (!clock.timers) {
clock.timers = {};
}

clock.timeouts[toId] = {
clock.timers[toId] = {
id: toId,
func: callback,
callAt: clock.now + delay,
Expand All @@ -161,21 +161,21 @@ function addTimer(clock, callback, opt) {
function firstTimerInRange(clock, from, to) {
var timer, smallest = null, originalTimer;

for (var id in clock.timeouts) {
if (!inRange(from, to, clock.timeouts[id])) {
for (var id in clock.timers) {
if (!inRange(from, to, clock.timers[id])) {
continue;
}

if (smallest === null || clock.timeouts[id].callAt < smallest) {
originalTimer = clock.timeouts[id];
smallest = clock.timeouts[id].callAt;
if (smallest === null || clock.timers[id].callAt < smallest) {
originalTimer = clock.timers[id];
smallest = clock.timers[id].callAt;

timer = {
func: clock.timeouts[id].func,
callAt: clock.timeouts[id].callAt,
interval: clock.timeouts[id].interval,
id: clock.timeouts[id].id,
invokeArgs: clock.timeouts[id].invokeArgs
func: clock.timers[id].func,
callAt: clock.timers[id].callAt,
interval: clock.timers[id].interval,
id: clock.timers[id].id,
invokeArgs: clock.timers[id].invokeArgs
};
}
}
Expand All @@ -185,9 +185,9 @@ function firstTimerInRange(clock, from, to) {

function callTimer(clock, timer) {
if (typeof timer.interval == "number") {
clock.timeouts[timer.id].callAt += timer.interval;
clock.timers[timer.id].callAt += timer.interval;
} else {
delete clock.timeouts[timer.id];
delete clock.timers[timer.id];
}

try {
Expand All @@ -200,7 +200,7 @@ function callTimer(clock, timer) {
var exception = e;
}

if (!clock.timeouts[timer.id]) {
if (!clock.timers[timer.id]) {
if (exception) {
throw exception;
}
Expand Down Expand Up @@ -292,16 +292,16 @@ var createClock = exports.createClock = function (now) {
// relied upon by some libraries, like Bootstrap carousel
return;
}
if (!clock.timeouts) {
clock.timeouts = [];
if (!clock.timers) {
clock.timers = [];
}
// in Node, timerId is an object with .ref()/.unref(), and
// its .id field is the actual timer id.
if (typeof timerId === "object") {
timerId = timerId.id
}
if (timerId in clock.timeouts) {
delete clock.timeouts[timerId];
if (timerId in clock.timers) {
delete clock.timers[timerId];
}
};

Expand All @@ -328,7 +328,7 @@ var createClock = exports.createClock = function (now) {

var firstException;
while (timer && tickFrom <= tickTo) {
if (clock.timeouts[timer.id]) {
if (clock.timers[timer.id]) {
tickFrom = clock.now = timer.callAt;
try {
callTimer(clock, timer);
Expand All @@ -351,7 +351,7 @@ var createClock = exports.createClock = function (now) {
};

clock.reset = function reset() {
clock.timeouts = {};
clock.timers = {};
};

return clock;
Expand Down

0 comments on commit 1e3d937

Please sign in to comment.