Skip to content

Commit

Permalink
avoid clobbering now(): rename to clock()
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Nov 27, 2019
1 parent f8beed8 commit 014f758
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions ag-solo-xs-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ import start from './lib/ag-solo/start';
trace("top-level executes\n");

function setImmediate(callback) {
Timer.set(callback);
// @@@not sure about this.
// https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/base/base.md#timer
// https://github.com/Agoric/SwingSet/issues/121
Timer.set(callback, 1);
}

function setInterval(callback, delay) {
Timer.repeat(callback, delay);
}

function now() {
function clock() {
return Date.now();
}

Expand Down Expand Up @@ -86,5 +89,5 @@ async function run(argv, cwd) {

const basedir = cwd.join(argv[0]);
return start(basedir, withSES, argv,
{ createServer, setImmediate, setInterval, now });
{ createServer, setImmediate, setInterval, clock });
}
8 changes: 4 additions & 4 deletions lib/ag-solo/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function buildSwingset(
vatsDir,
argv,
broadcast,
{ setInterval, setImmediate, now }
{ setInterval, setImmediate, clock }
) {
const initialMailboxState = JSON.parse(mailboxStateFile.readFileSync());

Expand Down Expand Up @@ -141,7 +141,7 @@ async function buildSwingset(
// drop calls to moveTimeForward if it's fallen behind, to make sure we don't
// have two copies of controller.run() executing at the same time.
function moveTimeForward() {
const now = Math.floor(now() / intervalMillis);
const now = Math.floor(clock() / intervalMillis);
if (timer.poll(now)) {
const p = processKernel();
p.then(
Expand All @@ -163,7 +163,7 @@ async function buildSwingset(
}

export default async function start(basedir, withSES, argv,
{ createServer, setImmediate, setInterval, now }) {
{ createServer, setImmediate, setInterval, clock }) {
console.log(`@@start(${basedir}, ${withSES}, ${argv})`);
const mailboxStateFile = basedir.join('swingset-mailbox-state.json');
const kernelStateFile = basedir.join('swingset-kernel-state.jsonlines');
Expand Down Expand Up @@ -240,7 +240,7 @@ export default async function start(basedir, withSES, argv,
vatsDir,
argv,
broadcast,
{ setInterval, setImmediate, now },
{ setInterval, setImmediate, clock },
);
({ deliverInboundToMbx, deliverInboundCommand } = d);

Expand Down

0 comments on commit 014f758

Please sign in to comment.