diff --git a/packages/daemon/src/guest.js b/packages/daemon/src/guest.js index 5eac205f60..4964352925 100644 --- a/packages/daemon/src/guest.js +++ b/packages/daemon/src/guest.js @@ -119,6 +119,7 @@ export const makeGuestMaker = ({ const external = Far('EndoGuest', { ...guest, followChanges: () => makeIteratorRef(guest.followChanges()), + followMessages: () => makeIteratorRef(guest.followMessages()), }); const internal = harden({ receive, diff --git a/packages/daemon/src/host.js b/packages/daemon/src/host.js index 1d66d45700..05bcc1a789 100644 --- a/packages/daemon/src/host.js +++ b/packages/daemon/src/host.js @@ -579,6 +579,7 @@ export const makeHostMaker = ({ const external = Far('EndoHost', { ...host, followChanges: () => makeIteratorRef(host.followChanges()), + followMessages: () => makeIteratorRef(host.followMessages()), }); const internal = harden({ receive, respond, petStore }); diff --git a/packages/daemon/src/mail.js b/packages/daemon/src/mail.js index 79c8fe4187..d56a526271 100644 --- a/packages/daemon/src/mail.js +++ b/packages/daemon/src/mail.js @@ -2,7 +2,6 @@ import { makePromiseKit } from '@endo/promise-kit'; import { makeChangeTopic } from './pubsub.js'; -import { makeIteratorRef } from './reader-ref.js'; import { assertPetName } from './pet-name.js'; const { quote: q } = assert; @@ -88,24 +87,21 @@ export const makeMailboxMaker = ({ const listMessages = async () => harden(Array.from(dubAndFilterMessages())); /** @type {import('./types.js').Mail['followMessages']} */ - const followMessages = async () => - makeIteratorRef( - (async function* currentAndSubsequentMessages() { - const subsequentRequests = messagesTopic.subscribe(); - for (const message of messages.values()) { - const dubbedMessage = dubMessage(message); - if (dubbedMessage !== undefined) { - yield dubbedMessage; - } - } - for await (const message of subsequentRequests) { - const dubbedMessage = dubMessage(message); - if (dubbedMessage !== undefined) { - yield dubbedMessage; - } - } - })(), - ); + const followMessages = async function* currentAndSubsequentMessages() { + const subsequentRequests = messagesTopic.subscribe(); + for (const message of messages.values()) { + const dubbedMessage = dubMessage(message); + if (dubbedMessage !== undefined) { + yield dubbedMessage; + } + } + for await (const message of subsequentRequests) { + const dubbedMessage = dubMessage(message); + if (dubbedMessage !== undefined) { + yield dubbedMessage; + } + } + }; /** * @param {object} partialMessage @@ -444,7 +440,6 @@ export const makeMailboxMaker = ({ return harden({ petStore: mailStore, - // Mail listMessages, followMessages, request, diff --git a/packages/daemon/src/types.d.ts b/packages/daemon/src/types.d.ts index 2d5f69e9aa..4f3c53f4aa 100644 --- a/packages/daemon/src/types.d.ts +++ b/packages/daemon/src/types.d.ts @@ -353,7 +353,7 @@ export interface Mail { petStore: PetStore; // Mail operations: listMessages(): Promise>; - followMessages(): Promise>>; + followMessages(): AsyncGenerator; resolve(messageNumber: number, resolutionName: string): Promise; reject(messageNumber: number, message?: string): Promise; adopt(