Skip to content

Commit

Permalink
refactor: clear up vow patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jun 24, 2024
1 parent 539fe41 commit cea3eb6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
13 changes: 10 additions & 3 deletions packages/async-flow/src/async-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { annotateError, Fail, makeError, q, X } from '@endo/errors';
import { E } from '@endo/eventual-send';
import { M } from '@endo/patterns';
import { makeScalarWeakMapStore } from '@agoric/store';
import { PromiseWatcherI } from '@agoric/base-zone';
import { prepareVowTools, toPassableCap, VowShape } from '@agoric/vow';
import {
prepareVowTools,
toPassableCap,
ReactionGuard,
VowShape,
} from '@agoric/vow';
import { makeReplayMembrane } from './replay-membrane.js';
import { prepareLogStore } from './log-store.js';
import { prepareBijection } from './bijection.js';
Expand Down Expand Up @@ -36,7 +40,10 @@ const AsyncFlowIKit = harden({
complete: M.call().returns(),
panic: M.call(M.error()).returns(M.not(M.any())), // only throws
}),
wakeWatcher: PromiseWatcherI,
wakeWatcher: M.interface('WakeWatcher', {
onFulfilled: ReactionGuard,
onRejected: ReactionGuard,
}),
});

const AdminAsyncFlowI = M.interface('AsyncFlowAdmin', {
Expand Down
2 changes: 1 addition & 1 deletion packages/base-zone/src/watch-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { Fail } = assert;
const { apply } = Reflect;

/**
* A PromiseWatcher method guard callable with or more arguments, returning void.
* A PromiseWatcher method guard callable with one or more arguments, returning void.
*/
export const PromiseWatcherHandler = M.call(M.any()).rest(M.any()).returns();

Expand Down
5 changes: 2 additions & 3 deletions packages/network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@
"dependencies": {
"@agoric/assert": "^0.6.0",
"@agoric/internal": "^0.3.2",
"@agoric/store": "^0.9.2",
"@agoric/vat-data": "^0.5.2",
"@agoric/vow": "^0.1.0",
"@endo/base64": "^1.0.5",
"@endo/far": "^1.1.2",
"@endo/pass-style": "^1.4.0",
"@endo/patterns": "^1.4.0",
"@endo/promise-kit": "^1.1.2"
},
"devDependencies": {
"@agoric/store": "^0.9.2",
"@agoric/swingset-liveslots": "^0.10.2",
"@agoric/swingset-vat": "^0.32.2",
"@agoric/vow": "^0.1.0",
"@agoric/zone": "^0.2.2",
"@endo/bundle-source": "^3.2.3",
"ava": "^5.3.0",
Expand Down
10 changes: 3 additions & 7 deletions packages/network/src/shapes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import { M } from '@endo/patterns';
import { VowShape, Vow$ } from '@agoric/vow';

const Shape1 = /** @type {const} */ ({
/**
Expand All @@ -9,12 +10,8 @@ const Shape1 = /** @type {const} */ ({
Data: M.string(),
Bytes: M.string(),
Endpoint: M.string(),
Vow: M.tagged(
'Vow',
harden({
vowV0: M.remotable('VowV0'),
}),
),
Vow$,
Vow: VowShape,
ConnectionHandler: M.remotable('ConnectionHandler'),
Connection: M.remotable('Connection'),
InboundAttempt: M.remotable('InboundAttempt'),
Expand All @@ -27,7 +24,6 @@ const Shape1 = /** @type {const} */ ({

const Shape2 = /** @type {const} */ ({
...Shape1,
Vow$: shape => M.or(shape, Shape1.Vow),
AttemptDescription: M.splitRecord(
{ handler: Shape1.ConnectionHandler },
{ remoteAddress: Shape1.Endpoint, localAddress: Shape1.Endpoint },
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/src/localchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { AmountShape, BrandShape, PaymentShape } from '@agoric/ertp';
import { Shape as NetworkShape } from '@agoric/network';
import { Vow$ } from '@agoric/vow';

const { Fail } = assert;
const { Vow$ } = NetworkShape;

Check failure on line 8 in packages/vats/src/localchain.js

View workflow job for this annotation

GitHub Actions / lint-primary

'Vow$' is already defined

Check failure on line 8 in packages/vats/src/localchain.js

View workflow job for this annotation

GitHub Actions / lint-primary

'Vow$' is read-only

Check failure on line 8 in packages/vats/src/localchain.js

View workflow job for this annotation

GitHub Actions / lint-primary

'NetworkShape' is not defined
Expand Down
7 changes: 1 addition & 6 deletions packages/vats/src/transfer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { ReactionGuard } from '@agoric/vow';
import { VTRANSFER_IBC_EVENT } from '@agoric/internal';
import { coerceToByteSource, byteSourceToBase64 } from '@agoric/network';
import { TargetAppI, AppTransformerI } from './bridge-target.js';
Expand All @@ -11,12 +12,6 @@ import { TargetAppI, AppTransformerI } from './bridge-target.js';

const { Fail, bare } = assert;

/**
* The least possibly restrictive guard for a `watch` watcher's `onFulfilled` or
* `onRejected` reaction
*/
const ReactionGuard = M.call(M.any()).optional(M.any()).returns(M.any());

/**
* @param {import('@agoric/base-zone').Zone} zone
* @param {import('@agoric/vow').VowTools} vowTools
Expand Down

0 comments on commit cea3eb6

Please sign in to comment.