Skip to content

Commit

Permalink
fix: enable type checking of zoe/tools and fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Oct 31, 2020
1 parent 6d562c3 commit 98f4637
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/zoe/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"strictNullChecks": true,
"moduleResolution": "node",
},
"include": ["src/**/*.js", "exports.js"],
"include": ["src/**/*.js", "exported.js", "tools/**/*.js"],
}
11 changes: 7 additions & 4 deletions packages/zoe/tools/manualTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import './internal-types';
export default function buildManualTimer(log, startValue = 0) {
let ticks = startValue;

/** @type {Store<Timestamp, Array<Waker>>} */
/** @type {Store<Timestamp, Array<TimerWaker>>} */
const schedule = makeStore('Timestamp');

/** @type {ManualTimer} */
Expand All @@ -43,7 +43,7 @@ export default function buildManualTimer(log, startValue = 0) {
if (baseTime <= ticks) {
log(`&& task was past its deadline when scheduled: ${baseTime} &&`);
E(waker).wake(ticks);
return undefined;
return baseTime;
}
log(`@@ schedule task for:${baseTime}, currently: ${ticks} @@`);
if (!schedule.has(baseTime)) {
Expand Down Expand Up @@ -72,10 +72,10 @@ export default function buildManualTimer(log, startValue = 0) {
return harden(baseTimes);
},
createRepeater(delay, interval) {
/** @type {Array<Waker> | null} */
/** @type {Array<TimerWaker> | null} */
let wakers = [];

/** @type {Waker} */
/** @type {TimerWaker} */
const repeaterWaker = {
async wake(timestamp) {
if (!wakers) {
Expand All @@ -91,6 +91,9 @@ export default function buildManualTimer(log, startValue = 0) {
/** @type {TimerRepeater} */
const repeater = {
schedule(waker) {
if (!wakers) {
throw Error(`Cannot schedule on a disabled repeater`);
}
wakers.push(waker);
},
disable() {
Expand Down
8 changes: 4 additions & 4 deletions packages/zoe/tools/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* schedule a single wake() call, create a repeater that will allow scheduling
* of events at regular intervals, or remove scheduled calls.
* @property {() => Timestamp} getCurrentTimestamp Retrieve the latest timestamp
* @property {(baseTime: Timestamp, waker: Waker) => Timestamp} setWakeup Return
* @property {(baseTime: Timestamp, waker: TimerWaker) => Timestamp} setWakeup Return
* value is the time at which the call is scheduled to take place
* @property {(waker: Waker) => Array<Timestamp>} removeWakeup Remove the waker
* @property {(waker: TimerWaker) => Array<Timestamp>} removeWakeup Remove the waker
* from all its scheduled wakeups, whether produced by `timer.setWakeup(h)` or
* `repeater.schedule(h)`.
* @property {(delay: RelativeTime, interval: RelativeTime) => TimerRepeater}
Expand All @@ -28,14 +28,14 @@
*/

/**
* @typedef {Object} Waker
* @typedef {Object} TimerWaker
* @property {(timestamp: Timestamp) => void} wake The timestamp passed to
* `wake()` is the time that the call was scheduled to occur.
*/

/**
* @typedef {Object} TimerRepeater
* @property {(waker: Waker) => void} schedule Returns the time scheduled for
* @property {(waker: TimerWaker) => void} schedule Returns the time scheduled for
* the first call to `E(waker).wake()`. The waker will continue to be scheduled
* every interval until the repeater is disabled.
* @property {() => void} disable Disable this repeater, so `schedule(w)` can't
Expand Down

0 comments on commit 98f4637

Please sign in to comment.