Skip to content

Commit

Permalink
fix: remove unnecessary types
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jul 8, 2020
1 parent 20941e6 commit e242143
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
6 changes: 5 additions & 1 deletion packages/SwingSet/src/vats/network/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const ENDPOINT_SEPARATOR = '/';
* @property {(port: Port, l: ListenHandler) => Promise<void>} [onListen] The listener has been registered
* @property {(port: Port, listenAddr: Endpoint, remoteAddr: Endpoint, l: ListenHandler) => Promise<Endpoint>} [onInbound] Return metadata for inbound connection attempt
* @property {(port: Port, localAddr: Endpoint, remoteAddr: Endpoint, l: ListenHandler) => Promise<ConnectionHandler>} onAccept A new connection is incoming
* @property {(port: Port, localAddr: Endpoint, remoteAddr: Endpoint, l: ListenHandler) => Promise<void>} onReject The connection was rejected
* @property {(port: Port, rej: any, l: ListenHandler) => Promise<void>} [onError] There was an error while listening
* @property {(port: Port, l: ListenHandler) => Promise<void>} [onRemove] The listener has been removed
*/
Expand Down Expand Up @@ -324,7 +325,10 @@ export function makeNetworkProtocol(protocolHandler, E = defaultE) {
if (localAddr.endsWith(ENDPOINT_SEPARATOR)) {
for (;;) {
// eslint-disable-next-line no-await-in-loop
const portID = await E(protocolHandler).generatePortID(localAddr);
const portID = await E(protocolHandler).generatePortID(
localAddr,
protocolHandler,
);
const newAddr = `${localAddr}${portID}`;
if (!boundPorts.has(newAddr)) {
localAddr = newAddr;
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import makeStore from '@agoric/store';
/**
* Create a handler that demuxes/muxes the bridge device by its first argument.
*
* @param {<T>(target: T) => T} E The eventual sender
* @param {import('@agoric/eventual-send').EProxy} E The eventual sender
* @param {<T>(target: Device<T>) => T} D The device sender
* @param {Device<BridgeDevice>} bridgeDevice The bridge to manage
* @returns {BridgeManager} admin facet for this handler
Expand Down
11 changes: 3 additions & 8 deletions packages/cosmic-swingset/lib/ag-solo/vats/ibc.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export function makeIBCProtocolHandler(E, callIBCDevice) {
localAddr,
remoteAddr,
);
const connP = /** @type {Promise<Connection, any>} */ (E.when(conn));
const connP = E.when(conn);
channelKeyToConnP.init(channelKey, connP);
},
onReceive,
Expand Down Expand Up @@ -515,14 +515,10 @@ EOF
const remoteAddr = `${ibcHops}/ibc-port/${rPortID}/${order.toLowerCase()}/${rVersion}`;

// See if we allow an inbound attempt for this address pair (without rejecting).
const attemptP =
/** @type {Promise<InboundAttempt>} */
(E(protocolImpl).inbound(localAddr, remoteAddr));
const attemptP = E(protocolImpl).inbound(localAddr, remoteAddr);

// Tell what version string we negotiated.
const attemptedLocal =
/** @type {string} */
(await E(attemptP).getLocalAddress());
const attemptedLocal = await E(attemptP).getLocalAddress();
const match = attemptedLocal.match(
// Match: ... /ORDER/VERSION ...
new RegExp('^(/[^/]+/[^/]+)*/(ordered|unordered)/([^/]+)(/|$)'),
Expand Down Expand Up @@ -643,7 +639,6 @@ EOF
E(connP)
.send(data)
.then(ack => {
/** @type {Data} */
const realAck = ack || DEFAULT_ACKNOWLEDGEMENT;
const ack64 = dataToBase64(realAck);
return callIBCDevice('packetExecuted', { packet, ack: ack64 });
Expand Down
13 changes: 9 additions & 4 deletions packages/eventual-send/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export const HandledPromise: HandledPromiseConstructor;

/* Types for E proxy calls. */
type ESingleMethod<T> = {
readonly [P in keyof T]: (...args: Parameters<T[P]>) => Promise<ReturnType<T[P]>>;
readonly [P in keyof T]: (...args: Parameters<T[P]>) => Promise<Unpromise<ReturnType<T[P]>>>;
}
type ESingleCall<T> = T extends Function ?
((...args: Parameters<T>) => Promise<ReturnType<T>>) & ESingleMethod<T> :
((...args: Parameters<T>) => Promise<Unpromise<ReturnType<T>>>) & ESingleMethod<T> :
ESingleMethod<T>;
type ESingleGet<T> = {
readonly [P in keyof T]: Promise<T[P]>;
readonly [P in keyof T]: Promise<Unpromise<T[P]>>;
}

/* Same types for send-only. */
Expand Down Expand Up @@ -84,12 +84,17 @@ interface EProxy {
*/
readonly G<T>(x: T): ESingleGet<Unpromise<T>>;

/**
* E.when(x) converts x to a promise.
*/
readonly when<T>(x: T): Promise<Unpromise<T>>;

/**
* E.when(x, res, rej) is equivalent to HandledPromise.resolve(x).then(res, rej)
*/
readonly when<T>(
x: T,
onfulfilled?: (value: Unpromise<T>) => any | PromiseLike<any>,
onfulfilled: (value: Unpromise<T>) => any | PromiseLike<any> | undefined,
onrejected?: (reason: any) => PromiseLike<never>,
): Promise<any>;

Expand Down

0 comments on commit e242143

Please sign in to comment.