Skip to content

Commit

Permalink
docs(vow): update for the current implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Aug 21, 2024
1 parent a513b30 commit 05eb6f0
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions packages/vow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Here they are: {
}
```

On Agoric, you can use `V` exported from `@agoric/vow/vat.js`, which
converts a chain of promises and vows to a promise for its final
fulfilment, by unwrapping any intermediate vows:
You can use `heapVowE` exported from `@agoric/vow`, which converts a chain of
promises and vows to a promise for its final fulfilment, by unwrapping any
intermediate vows:

```js
import { V as E } from '@agoric/vow/vat.js';
import { heapVowE as E } from '@agoric/vow';
[...]
const a = await E.when(w1);
const b = await E(w2).something(...args);
Expand All @@ -40,12 +40,13 @@ const b = await E(w2).something(...args);

## Vow Producer

On Agoric, use the following to create and resolve a vow:
Use the following to create and resolve a vow:

```js
// CAVEAT: `V` uses internal ephemeral promises, so while it is convenient,
// CAVEAT: `heapVow*` uses internal ephemeral promises, so while it is convenient,
// it cannot be used by upgradable vats. See "Durability" below:
import { V as E, makeVowKit } from '@agoric/vow/vat.js';
import { heapVowE, heapVowTools } from '@agoric/vow';
const { makeVowKit } = heapVowTools;
[...]
const { resolver, vow } = makeVowKit();
// Send vow to a potentially different vat.
Expand All @@ -56,15 +57,15 @@ resolver.resolve('now you know the answer');

## Durability

The `@agoric/vow/vat.js` module allows vows to integrate Agoric's vat upgrade
mechanism. To create vow tools that deal with durable objects:
By default, the `@agoric/vow` module allows vows to integrate with Agoric's vat
upgrade mechanism. To create vow tools that deal with durable objects:

```js
// NOTE: Cannot use `V` as it has non-durable internal state when unwrapping
// vows. Instead, use the default vow-exposing `E` with the `watch`
// operator.
import { E } from '@endo/far';
import { prepareVowTools } from '@agoric/vow/vat.js';
import { prepareVowTools } from '@agoric/vow';
import { makeDurableZone } from '@agoric/zone';

// Only do the following once at the start of a new vat incarnation:
Expand Down Expand Up @@ -94,20 +95,25 @@ final result:
// that may not be side-effect free.
let result = await specimenP;
let vowInternals = getVowInternals(result);
let disconnectionState = undefined;
// Loop until the result is no longer a vow.
while (vowInternals) {
try {
const shortened = await E(internals.vowV0).shorten();
// WARNING: Do not use `shorten()` in your own code. This is an example
// for didactic purposes only.
const shortened = await E(vowInternals.vowV0).shorten();
const nextInternals = getVowInternals(shortened);
// Atomically update the state.
result = shortened;
vowInternals = nextInternals;
} catch (e) {
if (!isDisconnectionReason(e)) {
const nextDisconnectionState = isDisconnectionReason(e, disconnectionState);
if (!nextDisconnectionState) {
// Not a disconnect, so abort.
throw e;
}
// It was a disconnect, so try again with the same state.
// It was a disconnect, so try again with the updated state.
disconnectionState = nextDisconnectionState;
}
}
return result;
Expand Down

0 comments on commit 05eb6f0

Please sign in to comment.