Skip to content

Commit

Permalink
feat(asyncFlow): E support
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed May 6, 2024
1 parent 7e3857c commit 2ad5c17
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
50 changes: 42 additions & 8 deletions packages/async-flow/src/replay-membrane.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { Fail, b, q } from '@endo/errors';
import { Far, Remotable, getInterfaceOf } from '@endo/pass-style';
import { E } from '@endo/eventual-send';
import { getMethodNames } from '@endo/eventual-send/utils.js';
import { makePromiseKit } from '@endo/promise-kit';
import { makeEquate } from './equate.js';
import { makeConvertKit } from './convert.js';

const { fromEntries, defineProperties } = Object;
const { fromEntries, defineProperties, assign } = Object;

/**
* @param {LogStore} log
Expand Down Expand Up @@ -195,6 +194,45 @@ export const makeReplayMembrane = (
}
};

// //////////////// Eventual Send ////////////////////////////////////////////

const guestHandler = harden({
applyMethod(guestTarget, verb, _guestArgs, _guestReturnedP) {
Fail`guest eventual send not yet supported: ${guestTarget}.${b(verb)}(...)`;
},
applyFunction(guestTarget, _guestArgs, _guestReturnedP) {
Fail`guest eventual call not yet supported: ${guestTarget}`;
},
get(guestPresence, prop) {
Fail`guest eventual get not yet supported: ${guestPresence}.${b(prop)}`;
},
});

const makeGuestPresence = (iface, methodEntries) => {
let guestPresence;
void new HandledPromise((_res, _rej, resolveWithPresence) => {
guestPresence = resolveWithPresence(guestHandler);
}); // no unfulfilledHandler
if (typeof guestPresence !== 'object') {
throw Fail`presence expected to be object ${guestPresence}`;
}
assign(guestPresence, fromEntries(methodEntries));
const result = Remotable(iface, undefined, guestPresence);
result === guestPresence ||
Fail`Remotable expected to make presence in place: ${guestPresence} vs ${result}`;
return result;
};

const makeGuestPromiseKit = () => {
let resolve;
let reject;
const promise = new HandledPromise((res, rej, _resPres) => {
resolve = res;
reject = rej;
}, guestHandler);
return harden({ promise, resolve, reject });
};

// //////////////// Converters ///////////////////////////////////////////////

const makeGuestForHostRemotable = hRem => {
Expand Down Expand Up @@ -234,18 +272,14 @@ export const makeReplayMembrane = (
name,
makeGuestMethod(name),
]);
// TODO in order to support E *well*,
// use HandledPromise to make gRem a remote presence for hRem
gRem = Remotable(guestIface, undefined, fromEntries(guestMethods));
gRem = makeGuestPresence(guestIface, guestMethods);
}
return gRem;
};
harden(makeGuestForHostRemotable);

const makeGuestForHostVow = hVow => {
// TODO in order to support E *well*,
// use HandledPromise to make `promise` a handled promise for hVow
const { promise, resolve, reject } = makePromiseKit();
const { promise, resolve, reject } = makeGuestPromiseKit();
guestPromiseMap.set(promise, harden({ resolve, reject }));

watchWake(hVow);
Expand Down
14 changes: 7 additions & 7 deletions packages/async-flow/src/type-guards.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ export const LogEntryShape = M.or(
M.arrayOf(M.any()),
M.number(),
],
// [
// 'checkSend',
// M.or(M.remotable('host target'), VowShape),
// M.opt(PropertyKeyShape),
// M.arrayOf(M.any()),
// M.number(),
// ],
[
'checkSend',
M.or(M.remotable('host target'), VowShape),
M.opt(PropertyKeyShape),
M.arrayOf(M.any()),
M.number(),
],
// ['checkReturn', M.number(), M.any()],
// ['checkThrow', M.number(), M.any()],
);
6 changes: 6 additions & 0 deletions packages/async-flow/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
* optVerb: PropertyKey|undefined,
* args: Host[],
* callIndex: number
* ] | [
* op: 'checkSend',
* target: Host,
* optVerb: PropertyKey|undefined,
* args: Host[],
* callIndex: number
* ]} LogEntry
*/

Expand Down

0 comments on commit 2ad5c17

Please sign in to comment.