Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vowTools): add asVow helper #9577

Merged
merged 2 commits into from
Jun 25, 2024
Merged

feat(vowTools): add asVow helper #9577

merged 2 commits into from
Jun 25, 2024

Conversation

0xpatrickdev
Copy link
Member

@0xpatrickdev 0xpatrickdev commented Jun 24, 2024

refs: #9449

Description

Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very quick review, LGTM

Comment on lines 88 to 99
const kit = makeVowKit();
try {
kit.resolver.resolve(fn());
} catch (e) {
kit.resolver.reject(e);
}
return kit.vow;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could simply support not resolving a vow to a vow with the following:

Suggested change
const kit = makeVowKit();
try {
kit.resolver.resolve(fn());
} catch (e) {
kit.resolver.reject(e);
}
return kit.vow;
let result;
try {
result = fn();
} catch (e) {
result = Promise.reject(e);
}
if (isVow(result)) {
return result;
}
const kit = makeVowKit();
kit.resolver.resolve(result);
return kit.vow;

packages/vow/test/asVow.test.js Show resolved Hide resolved
Copy link

cloudflare-workers-and-pages bot commented Jun 25, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0cdcd5f
Status: ✅  Deploy successful!
Preview URL: https://d8e8131b.agoric-sdk.pages.dev
Branch Preview URL: https://pc-as-vow.agoric-sdk.pages.dev

View logs

@0xpatrickdev 0xpatrickdev changed the base branch from 9449-chain-account-vows to master June 25, 2024 01:40
@0xpatrickdev 0xpatrickdev marked this pull request as ready for review June 25, 2024 01:42
Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the small test feedback is addressed

packages/vow/test/asVow.test.js Outdated Show resolved Hide resolved
const testVow = watch(Promise.resolve('payload'));
const testVowAsVow = asVow(() => testVow);

t.is(testVow, testVowAsVow, 'asVow does not rewrap vows');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So technically we should do a "passable compare" here. The tagged vow could be a different object, but the nested payload must contain the same remotable. Not sure if we have a common way to do such passable comparisons.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closest thing I'm aware of is getInterfaceOf, which doesn't quite seem to fit the bill for a "passable compare".

In this testing context, where there's no disconnection, this was a cheap way to verify the behavior. I added a comment with this feedback and context above this line.

@0xpatrickdev 0xpatrickdev added the automerge:rebase Automatically rebase updates, then merge label Jun 25, 2024
- adds asVow() helper function that coerces the result of a function to a Vow
- see comment from @mhofman for inspiration: #9454 (comment)
@mergify mergify bot merged commit 0ad10c6 into master Jun 25, 2024
77 checks passed
@mergify mergify bot deleted the pc/as-vow branch June 25, 2024 16:13
gibson042 pushed a commit that referenced this pull request Jul 2, 2024
refs: #9449

## Description

- Add `asVow` helper to `VowTools` to ensure we always return vows, even in the event of early synchronous errors.
- Implement the helper in `ChainAccountKit` against #9562
gibson042 added a commit that referenced this pull request Jul 2, 2024
git rebase-todo
```
# Branch pc/as-vow
label base-pc-as-vow
pick b6b5f5f feat(vowTools): add asVow helper
pick 0cdcd5f feat(vowTools): asVow should not wrap a vow as a vow
label pc-as-vow
reset base-pc-as-vow
merge -C 0ad10c6 pc-as-vow # feat(vowTools): add asVow helper (#9577)

# Branch pc/watch-utils-as-promise
label base-pc-watch-utils-as-promise
pick bf430a1 feat(watchUtils): add asPromise helper
# To resolve conflicts in the following commit:
# * In packages/vow/src/types.js, keep inbound changes and (after that) the
#   definition of VowTools.
# * In packages/vow/test/watch-utils.test.js, keep only inbound changes and
#   limit them to start at "asPromise converts a vow to a promise" (i.e.,
#   just the additions of
#   https://github.com/Agoric/agoric-sdk/pull/9620/files#diff-fd7cabcc7d1097036e2981c3262aa20612bec349f6e418d53324fc33b1b26946 ).
pick c940d5c feat(vowTools): asPromise helper for unwrapping vows
pick 8c27c67 feat(watchUtils): handle non-storables
pick 3d5a3f3 feat(types): EVow
pick 1c0b964 refactor: don't re-use index
pick 274df18 fix(vow): clearer stored/non-stored values
pick ff92211 refactor: 'extra' field for future properties
label pc-watch-utils-as-promise
reset base-pc-watch-utils-as-promise
merge -C 8edf902 pc-watch-utils-as-promise # feat(vows): improve handling of ephemeral values (#9620)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants