diff --git a/packages/xsnap/src/defer.js b/packages/xsnap/src/defer.js deleted file mode 100644 index cd3d70f2c63..00000000000 --- a/packages/xsnap/src/defer.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @param {boolean} _flag - * @returns {asserts _flag} - */ - -function assert(_flag) {} - -/** - * @template T - * @typedef {{ - * resolve(value?: T | Promise): void, - * reject(error: Error): void, - * promise: Promise - * }} Deferred - */ - -/** - * @template T - * @returns {Deferred} - */ -export function defer() { - let resolve; - let reject; - const promise = new Promise((res, rej) => { - resolve = res; - reject = rej; - }); - assert(resolve !== undefined); - assert(reject !== undefined); - return { promise, resolve, reject }; -} diff --git a/packages/xsnap/src/xsnap.js b/packages/xsnap/src/xsnap.js index a0fe1baa5b2..a6a87223330 100644 --- a/packages/xsnap/src/xsnap.js +++ b/packages/xsnap/src/xsnap.js @@ -10,18 +10,14 @@ import { makeNodeReader, makeNodeWriter } from '@endo/stream-node'; import { makePromiseKit, racePromises } from '@endo/promise-kit'; import { forever } from '@agoric/internal'; import { ErrorCode, ErrorSignal, ErrorMessage, METER_TYPE } from '../api.js'; -import { defer } from './defer.js'; + +/** @import {PromiseKit} from '@endo/promise-kit' */ /** * @typedef {typeof import('child_process').spawn} Spawn * @import {Writable} from 'stream' */ -/** - * @template T - * @typedef {import('./defer.js').Deferred} Deferred - */ - // This will need adjustment, but seems to be fine for a start. export const DEFAULT_CRANK_METERING_LIMIT = 1e8; @@ -185,8 +181,8 @@ export async function xsnap(options) { import.meta.url, ).pathname; - /** @type {Deferred} */ - const vatExit = defer(); + /** @type {PromiseKit} */ + const vatExit = makePromiseKit(); assert(!/^-/.test(name), `name '${name}' cannot start with hyphen`); diff --git a/packages/xsnap/src/xsrepl.js b/packages/xsnap/src/xsrepl.js index 4581e48713f..3eede346bba 100755 --- a/packages/xsnap/src/xsrepl.js +++ b/packages/xsnap/src/xsrepl.js @@ -4,17 +4,15 @@ import '@endo/init'; -/** - * @template T - * @typedef {import('./defer.js').Deferred} Deferred - */ import * as childProcess from 'child_process'; import fs from 'fs'; import { tmpName } from 'tmp'; import * as os from 'os'; import * as readline from 'readline'; +import { makePromiseKit } from '@endo/promise-kit'; import { xsnap } from './xsnap.js'; -import { defer } from './defer.js'; + +/** @import {PromiseKit} from '@endo/promise-kit' */ const decoder = new TextDecoder(); @@ -65,7 +63,9 @@ async function main() { * @returns {Promise} */ function ask(prompt) { - const { promise, resolve } = /** @type {Deferred} */ (defer()); + const { promise, resolve } = /** @type {PromiseKit} */ ( + makePromiseKit() + ); rl.question(prompt, resolve); return promise; }