Skip to content

Commit

Permalink
feat(zone): asyncFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Mar 22, 2024
1 parent 0025f91 commit 0ccd48f
Show file tree
Hide file tree
Showing 28 changed files with 2,719 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/SwingSet/src/controller/initializeKernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export async function initializeKernel(config, kernelStorage, options = {}) {
serializeBodyFormat: 'smallcaps',
// TODO Temporary hack.
// See https://github.com/Agoric/agoric-sdk/issues/2780
errorIdNum: 60000,
errorIdNum: 60_000,
});
const args = kunser(m.serialize(harden([vatObj0s, deviceObj0s])));
const rootKref = exportRootObject(kernelKeeper, bootstrapVatID);
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/devices/lib/deviceTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ export function buildSerializationTools(syscall, deviceName) {
}

const m = makeMarshal(convertValToSlot, convertSlotToVal, {
marshalName: `device:${deviceName}`,
marshalName: `deviceTools:${deviceName}`,
serializeBodyFormat: 'smallcaps',
// TODO Temporary hack.
// See https://github.com/Agoric/agoric-sdk/issues/2780
errorIdNum: 60000,
errorIdNum: 40_000,
});

// for invoke(), these will unserialize the arguments, and serialize the
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/deviceSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function makeDeviceSlots(
serializeBodyFormat: 'smallcaps',
// TODO Temporary hack.
// See https://github.com/Agoric/agoric-sdk/issues/2780
errorIdNum: 50000,
errorIdNum: 50_000,
});

function PresenceHandler(importSlot) {
Expand Down
2 changes: 1 addition & 1 deletion packages/swingset-liveslots/src/liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ function build(
serializeBodyFormat: 'smallcaps',
// TODO Temporary hack.
// See https://github.com/Agoric/agoric-sdk/issues/2780
errorIdNum: 70000,
errorIdNum: 70_000,
marshalSaveError: err =>
// By sending this to `console.warn`, under cosmic-swingset this is
// controlled by the `console` option given to makeLiveSlots.
Expand Down
8 changes: 6 additions & 2 deletions packages/swingset-liveslots/src/watchedPromises.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// no-lonely-if is a stupid rule that really should be disabled globally
/* eslint-disable no-lonely-if */

import { Fail } from '@endo/errors';
import { E } from '@endo/eventual-send';
import { assert } from '@agoric/assert';
import { initEmpty, M } from '@agoric/store';
import { E } from '@endo/eventual-send';
import { parseVatSlot } from './parseVatSlots.js';

/**
Expand Down Expand Up @@ -198,7 +199,10 @@ export function makeWatchedPromiseManager({
const watcherVref = convertValToSlot(watcher);
assert(watcherVref, 'invalid watcher');
const { virtual, durable } = parseVatSlot(watcherVref);
assert(virtual || durable, 'promise watcher must be a virtual object');
virtual ||
durable ||
// separate line so easy to breakpoint on
Fail`promise watcher must be a virtual object`;
if (watcher.onFulfilled) {
assert.typeof(watcher.onFulfilled, 'function');
}
Expand Down
3 changes: 3 additions & 0 deletions packages/swingset-liveslots/tools/fakeVirtualSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ export function makeFakeLiveSlotsStuff(options = {}) {

const marshal = makeMarshal(convertValToSlot, convertSlotToVal, {
serializeBodyFormat: 'smallcaps',
marshalName: 'fakeLiveSlots',
errorIdNum: 80_000,
marshalSaveError: _err => {},
});

function registerEntry(baseRef, val, valIsCohort) {
Expand Down
1 change: 1 addition & 0 deletions packages/vow/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
export * from './tools.js';
export { default as makeE } from './E.js';
export { VowShape } from './vow-utils.js';

// eslint-disable-next-line import/export
export * from './types.js';
8 changes: 8 additions & 0 deletions packages/vow/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,11 @@ export {};
* @template [T=any]
* @typedef {import('./types.js').ERef<T | import('./types.js').Vow<T>>} Specimen
*/

/**
* @typedef {object} VowTools
* // TODO type according to prepareWatch returns
* @property {(specimenP:any, watcher?:any, watcherContext?:any) => Vow} watch
* @property {(specimenP:any, onFulfilled?:any, onRejected?:any) => Promise} when
* @property {() => VowKit} makeVowKit
*/
24 changes: 15 additions & 9 deletions packages/vow/src/vow-utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
// @ts-check
import { E as basicE } from '@endo/eventual-send';
import { getTag, passStyleOf } from '@endo/pass-style';

// TODO: `isPassable` should come from @endo/pass-style
import { isPassable } from '@agoric/base-zone';
import { isPassable } from '@endo/pass-style';
import { M, matches } from '@endo/patterns';

export { basicE };

export const VowShape = M.tagged(
'Vow',
M.splitRecord({
vowV0: M.remotable('VowV0'),
}),
);

export const isVow = specimen =>
isPassable(specimen) && matches(specimen, VowShape);
harden(isVow);

/**
* A vow is a passable tagged as 'Vow'. Its payload is a record with
* API-versioned remotables. payload.vowV0 is the API for the `watch` and
Expand All @@ -19,11 +28,7 @@ export { basicE };
* @returns {import('./types').VowPayload<T> | undefined} undefined if specimen is not a vow, otherwise the vow's payload.
*/
export const getVowPayload = specimen => {
const isVow =
isPassable(specimen) &&
passStyleOf(specimen) === 'tagged' &&
getTag(specimen) === 'Vow';
if (!isVow) {
if (!isVow(specimen)) {
return undefined;
}

Expand All @@ -32,3 +37,4 @@ export const getVowPayload = specimen => {
);
return vow.payload;
};
harden(getVowPayload);
2 changes: 1 addition & 1 deletion packages/wallet/api/src/lib-dehydrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export const makeDehydrator = (initialUnnamedCount = 0) => {
marshalName: 'hydration',
// TODO Temporary hack.
// See https://github.com/Agoric/agoric-sdk/issues/2780
errorIdNum: 30000,
errorIdNum: 30_000,
serializeBodyFormat: 'smallcaps',
},
);
Expand Down
15 changes: 13 additions & 2 deletions packages/zone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"exports": {
".": "./src/index.js",
"./zone-helpers.js": "./zone-helpers.js",
"./durable.js": "./durable.js",
"./heap.js": "./heap.js",
"./virtual.js": "./virtual.js"
Expand All @@ -28,13 +29,23 @@
"license": "Apache-2.0",
"dependencies": {
"@agoric/base-zone": "^0.1.0",
"@agoric/store": "^0.9.2",
"@agoric/vow": "^0.1.0",
"@agoric/vat-data": "^0.5.2",
"@endo/far": "^1.1.0",
"@endo/pass-style": "^1.3.0"
"@endo/pass-style": "^1.3.0",
"@endo/common": "^1.2.0",
"@endo/errors": "^1.2.0",
"@endo/eventual-send": "^1.2.0",
"@endo/marshal": "^1.4.0",
"@endo/patterns": "^1.3.0",
"@endo/promise-kit": "^1.1.0"
},
"devDependencies": {
"@agoric/internal": "^0.3.2",
"@agoric/swingset-liveslots": "^0.10.2",
"@endo/patterns": "^1.3.0",
"@endo/env-options": "^1.1.2",
"@endo/ses-ava": "^1.2.0",
"ava": "^5.3.0"
},
"publishConfig": {
Expand Down
Loading

0 comments on commit 0ccd48f

Please sign in to comment.