Skip to content

Commit

Permalink
feat: (prospectively) use watchPromise() to wait for contract finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Oct 12, 2023
1 parent d4b32f1 commit 802141b
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions packages/zoe/src/zoeService/startInstance.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global globalThis */

/* eslint @typescript-eslint/no-floating-promises: "warn" */
import { E } from '@endo/eventual-send';
import { passStyleOf } from '@endo/marshal';
Expand All @@ -6,6 +8,7 @@ import {
makeScalarBigMapStore,
provideDurableWeakMapStore,
prepareExoClass,
prepareExo,
} from '@agoric/vat-data';
import { initEmpty } from '@agoric/store';

Expand Down Expand Up @@ -131,10 +134,10 @@ export const makeStartInstance = (
replaceAllocations(seatHandleAllocations) {
const { state } = this;
try {
seatHandleAllocations.forEach(({ seatHandle, allocation }) => {
for (const { seatHandle, allocation } of seatHandleAllocations) {
const zoeSeatAdmin = state.seatHandleToSeatAdmin.get(seatHandle);
zoeSeatAdmin.replaceAllocation(allocation);
});
}
} catch (err) {
// nothing for Zoe to do if the termination fails
void E(state.adminNode).terminateWithFailure(err);
Expand Down Expand Up @@ -225,6 +228,20 @@ export const makeStartInstance = (
},
);

const watcher = prepareExo(
zoeBaggage,
'InstanceCompletionWatcher',
M.interface('InstanceCompletionWatcher', {
onFulfilled: M.call(M.any()).returns(),
onRejected: M.call(M.any()).returns(),
}),
{
onFulfilled: (completion, instanceAdmin) =>
instanceAdmin.exitAllSeats(completion),
onRejected: (reason, instanceAdmin) => instanceAdmin.failAllSeats(reason),
},
);

const startInstance = async (
installationP,
uncleanIssuerKeywordRecord = harden({}),
Expand Down Expand Up @@ -278,12 +295,10 @@ export const makeStartInstance = (
);
zoeInstanceStorageManager.initInstanceAdmin(instanceHandle, instanceAdmin);

E.when(
globalThis.VatData.watchPromise(
E(adminNode).done(),
completion => {
instanceAdmin.exitAllSeats(completion);
},
reason => instanceAdmin.failAllSeats(reason),
watcher,
instanceAdmin,
);

/** @type {ZoeInstanceAdmin} */
Expand Down

0 comments on commit 802141b

Please sign in to comment.