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: clean up E.when and E.resolve #1561

Merged
merged 3 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 8 additions & 7 deletions packages/ERTP/src/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { assert, details } from '@agoric/assert';
import makeStore from '@agoric/weak-store';
import { E } from '@agoric/eventual-send';
import { isPromise } from '@agoric/promise-kit';

import { makeAmountMath, MathKind } from './amountMath';
Expand All @@ -20,7 +21,7 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) {

const brand = harden({
isMyIssuer: allegedIssuerP => {
return Promise.resolve(allegedIssuerP).then(allegedIssuer => {
return E.when(allegedIssuerP, allegedIssuer => {
// eslint-disable-next-line no-use-before-define
return allegedIssuer === issuer;
});
Expand Down Expand Up @@ -185,19 +186,19 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) {
},

isLive: paymentP => {
return Promise.resolve(paymentP).then(payment => {
return E.when(paymentP, payment => {
return paymentLedger.has(payment);
});
},
getAmountOf: paymentP => {
return Promise.resolve(paymentP).then(payment => {
return E.when(paymentP, payment => {
assertKnownPayment(payment);
return paymentLedger.get(payment);
});
},

burn: (paymentP, optAmount = undefined) => {
return Promise.resolve(paymentP).then(payment => {
return E.when(paymentP, payment => {
assertKnownPayment(payment);
const paymentBalance = paymentLedger.get(payment);
assertAmountEqual(paymentBalance, optAmount);
Expand All @@ -207,7 +208,7 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) {
});
},
claim: (paymentP, optAmount = undefined) => {
return Promise.resolve(paymentP).then(srcPayment => {
return E.when(paymentP, srcPayment => {
assertKnownPayment(srcPayment);
const srcPaymentBalance = paymentLedger.get(srcPayment);
assertAmountEqual(srcPaymentBalance, optAmount);
Expand Down Expand Up @@ -242,7 +243,7 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) {
},
// payment to two payments, A and B
split: (paymentP, paymentAmountA) => {
return Promise.resolve(paymentP).then(srcPayment => {
return E.when(paymentP, srcPayment => {
paymentAmountA = amountMath.coerce(paymentAmountA);
assertKnownPayment(srcPayment);
const srcPaymentBalance = paymentLedger.get(srcPayment);
Expand All @@ -261,7 +262,7 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) {
});
},
splitMany: (paymentP, amounts) => {
return Promise.resolve(paymentP).then(srcPayment => {
return E.when(paymentP, srcPayment => {
assertKnownPayment(srcPayment);
amounts = amounts.map(amountMath.coerce);
// Commit point
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/ibc.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function makeIBCProtocolHandler(E, callIBCDevice) {
localAddr,
remoteAddr,
);
const connP = E.when(conn);
const connP = E.resolve(conn);
channelKeyToConnP.init(channelKey, connP);
},
onReceive,
Expand Down
6 changes: 3 additions & 3 deletions packages/eventual-send/src/E.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// eslint-disable-next-line spaced-comment
/// <reference path="index.d.ts" />

const readOnlyProxy = {
const readOnlyProxyHandler = {
set(_target, _prop, _value) {
return false;
},
Expand All @@ -26,7 +26,7 @@ const readOnlyProxy = {
*/
function EProxyHandler(x, HandledPromise) {
return harden({
...readOnlyProxy,
...readOnlyProxyHandler,
get(_target, p, _receiver) {
if (`${p}` !== p) {
return undefined;
Expand Down Expand Up @@ -56,7 +56,7 @@ export default function makeE(HandledPromise) {

const makeEGetterProxy = x =>
new Proxy(Object.create(null), {
...readOnlyProxy,
...readOnlyProxyHandler,
has(_target, _prop) {
return true;
},
Expand Down
5 changes: 3 additions & 2 deletions packages/eventual-send/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ interface EProxy {
readonly G<T>(x: T): ESingleGet<Unpromise<T>>;

/**
* E.when(x) converts x to a promise.
* E.resolve(x) converts x to a handled promise. It is
* shorthand for HandledPromise.resolve(x)
*/
readonly when<T>(x: T): Promise<Unpromise<T>>;
readonly resolve<T>(x: T): Promise<Unpromise<T>>;

/**
* E.when(x, res, rej) is equivalent to
Expand Down
3 changes: 2 additions & 1 deletion packages/marshal/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const remotableToInterface = new WeakMap();
* Simple semantics, just tell what interface (or undefined) a remotable has.
*
* @param {*} maybeRemotable the value to check
* @returns {InterfaceSpec|undefined} the interface specification, or undefined if not a Remotable
* @returns {InterfaceSpec|undefined} the interface specification, or undefined
* if not a Remotable
*/
export function getInterfaceOf(maybeRemotable) {
return remotableToInterface.get(maybeRemotable);
Expand Down
3 changes: 2 additions & 1 deletion packages/notifier/src/asyncIterableAdaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export const updateFromIterable = (updater, asyncIterable) => {
const iterator = asyncIterable[Symbol.asyncIterator]();
return new Promise(ack => {
const recur = () => {
E.when(iterator.next()).then(
E.when(
iterator.next(),
({ value, done }) => {
if (done) {
updater.finish && updater.finish(value);
Expand Down
4 changes: 3 additions & 1 deletion packages/notifier/test/test-notifier-adaptor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import '@agoric/install-ses';
import { E } from '@agoric/eventual-send';
import test from 'tape-promise/tape';
import {
makeAsyncIterableFromNotifier,
Expand Down Expand Up @@ -42,7 +43,8 @@ const finiteStream = makeIterable(false);
const explodingStream = makeIterable(true);

const testEnding = (t, p, fails) => {
return Promise.resolve(p).then(
return E.when(
erights marked this conversation as resolved.
Show resolved Hide resolved
p,
result => {
t.equal(fails, false);
t.equal(result, refResult);
Expand Down