diff --git a/packages/async-flow/src/replay-membrane.js b/packages/async-flow/src/replay-membrane.js index eb68f58de44..ad2685d7c68 100644 --- a/packages/async-flow/src/replay-membrane.js +++ b/packages/async-flow/src/replay-membrane.js @@ -414,11 +414,19 @@ export const makeReplayMembrane = ( /** * @param {Vow} hVow + * @param {Promise} [promiseKey] + * If provided, use this promise as the key in the guestPromiseMap + * rather than the returned promise. This only happens when the + * promiseKey ends up forwarded to the returned promise anyway, so + * associating it with this resolve/reject pair is not incorrect. + * It is needed when `promiseKey` is also entered into the bijection + * paired with hVow. * @returns {Promise} */ - const makeGuestForHostVow = hVow => { + const makeGuestForHostVow = (hVow, promiseKey = undefined) => { const { promise, resolve, reject } = makeGuestPromiseKit(); - guestPromiseMap.set(promise, harden({ resolve, reject })); + promiseKey ??= promise; + guestPromiseMap.set(promiseKey, harden({ resolve, reject })); watchWake(hVow); @@ -442,7 +450,7 @@ export const makeReplayMembrane = ( hVow, async hostFulfillment => { await log.promiseReplayDone(); // should never reject - if (!stopped && guestPromiseMap.get(promise) !== 'settled') { + if (!stopped && guestPromiseMap.get(promiseKey) !== 'settled') { /** @type {LogEntry} */ const entry = harden(['doFulfill', hVow, hostFulfillment]); log.pushEntry(entry); @@ -457,7 +465,7 @@ export const makeReplayMembrane = ( }, async hostReason => { await log.promiseReplayDone(); // should never reject - if (!stopped && guestPromiseMap.get(promise) !== 'settled') { + if (!stopped && guestPromiseMap.get(promiseKey) !== 'settled') { /** @type {LogEntry} */ const entry = harden(['doReject', hVow, hostReason]); log.pushEntry(entry);