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

fix(vow): fix vow bug instead #9702

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/async-flow/src/replay-membrane.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ export const makeReplayMembrane = ({
}
}
},
).catch(reject);
);
return promise;
};
harden(makeGuestForHostVow);
Expand Down
81 changes: 44 additions & 37 deletions packages/vow/src/when.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,54 @@ export const makeWhen = (
// Ensure we don't run until a subsequent turn.
await null;

// Ensure we have a presence that won't be disconnected later.
let result = await specimenP;
let payload = getVowPayload(result);
let priorRetryValue;
const seenPayloads = new WeakSet();
while (payload) {
// TODO: rely on endowed helpers for getting storable cap and performing
// shorten "next step"
const { vowV0 } = payload;
if (seenPayloads.has(vowV0)) {
throw Error('Vow resolution cycle detected');
try {
// Ensure we have a presence that won't be disconnected later.
let result = await specimenP;
let payload = getVowPayload(result);
let priorRetryValue;
const seenPayloads = new WeakSet();
while (payload) {
// TODO: rely on endowed helpers for getting storable cap and performing
// shorten "next step"
const { vowV0 } = payload;
if (seenPayloads.has(vowV0)) {
throw Error('Vow resolution cycle detected');
}
result = await basicE(vowV0)
.shorten()
.then(
res => {
seenPayloads.add(vowV0);
priorRetryValue = undefined;
return res;
},
e => {
const nextValue = isRetryableReason(e, priorRetryValue);
if (nextValue) {
// Shorten the same specimen to try again.
priorRetryValue = nextValue;
return result;
}
throw e;
},
);
// Advance to the next vow.
payload = getVowPayload(result);
}
result = await basicE(vowV0)
.shorten()
.then(
res => {
seenPayloads.add(vowV0);
priorRetryValue = undefined;
return res;
},
e => {
const nextValue = isRetryableReason(e, priorRetryValue);
if (nextValue) {
// Shorten the same specimen to try again.
priorRetryValue = nextValue;
return result;
}
throw e;
},
);
// Advance to the next vow.
payload = getVowPayload(result);
}

const unwrapped = /** @type {EUnwrap<T>} */ (result);
const unwrapped = /** @type {EUnwrap<T>} */ (result);

// We've extracted the final result.
if (onFulfilled == null && onRejected == null) {
return /** @type {TResult1} */ (unwrapped);
// We've extracted the final result.
if (onFulfilled == null && onRejected == null) {
return /** @type {TResult1} */ (unwrapped);
}
return basicE.resolve(unwrapped).then(onFulfilled, onRejected);
} catch (thrownReason) {
if (onRejected == null) {
throw thrownReason;
}
return onRejected(thrownReason);
}
return basicE.resolve(unwrapped).then(onFulfilled, onRejected);
};
harden(when);

Expand Down
Loading