Skip to content

Commit

Permalink
fix: properly postpone multiple arguments
Browse files Browse the repository at this point in the history
also:
fixes #9
fixes #12
  • Loading branch information
michaelfig committed Jul 11, 2019
1 parent 443da01 commit 54d53d4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agoric/eventual-send",
"version": "0.1.3",
"version": "0.1.3-next",
"description": "Extend a Promise class to implement the eventual-send API",
"main": "dist/eventual-send.cjs.js",
"module": "dist/eventual-send.esm.js",
Expand Down
7 changes: 2 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export default function maybeExtendPromise(Promise) {

// This special handler accepts Promises, and forwards
// handled Promises to their corresponding resolvedHandler.
//
// If passed a Promise that is not handled, perform
// the corresponding local operation.
let forwardingHandler;
function handler(p) {
return promiseToHandler.get(p) || forwardingHandler;
Expand Down Expand Up @@ -101,7 +98,7 @@ export default function maybeExtendPromise(Promise) {
return async (p, ...args) => {
// console.log(`forwarding ${forwardedOperation}`);
await handlerP;
return p[forwardedOperation](args);
return p[forwardedOperation](...args);
};
};

Expand Down Expand Up @@ -167,7 +164,7 @@ export default function maybeExtendPromise(Promise) {

if (resolveTheHandler) {
// Activate the default unresolvedHandler.
resolveTheHandler(resolvedHandler);
resolveTheHandler(null);
}
} catch (e) {
rejectHandled(e);
Expand Down
7 changes: 4 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ test('EPromise.makeHandled(executor, undefined)', async t => {
const o = {
num: 123,
str: 'my string',
hello(name) {
return `Hello, ${name}!`;
hello(name, punct = '') {
return `Hello, ${name}${punct}`;
},
};

Expand All @@ -152,6 +152,7 @@ test('EPromise.makeHandled(executor, undefined)', async t => {
}, 200);
});

t.equal(await remoteP.post('hello', ['World', '!']), 'Hello, World!');
t.equal(await remoteP.get('str'), 'my string');
t.equal(await remoteP.get('num'), 123);
t.equal(await remoteP.put('num', 789), 789);
Expand All @@ -160,7 +161,7 @@ test('EPromise.makeHandled(executor, undefined)', async t => {
t.equal(await remoteP.get('str'), undefined);
t.equal(await remoteP.delete('str'), true);
t.equal(await remoteP.get('str'), undefined);
t.equal(await remoteP.invoke('hello', 'World'), 'Hello, World!');
t.equal(await remoteP.invoke('hello', 'World'), 'Hello, World');
} catch (e) {
t.assert(false, `Unexpected exception ${e}`);
} finally {
Expand Down

0 comments on commit 54d53d4

Please sign in to comment.