Skip to content

Commit

Permalink
feat: add the returnedP as the last argument to the handler
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Apr 11, 2020
1 parent 3135d9a commit 1f83d99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions packages/eventual-send/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ export function makeHandledPromise(Promise) {
p = shorten(p);
const unfulfilledHandler = promiseToHandler.get(p);
let executor;
let returnedP;
if (
unfulfilledHandler &&
typeof unfulfilledHandler[operation] === 'function'
Expand All @@ -448,7 +449,7 @@ export function makeHandledPromise(Promise) {
HandledPromise.resolve()
.then(() =>
// and resolve to the answer from the specific unfulfilled handler,
resolve(unfulfilledHandler[operation](p, ...args)),
resolve(unfulfilledHandler[operation](p, ...args, returnedP)),
)
.catch(reject);
};
Expand All @@ -464,7 +465,7 @@ export function makeHandledPromise(Promise) {
);
}
// and resolve to the forwardingHandler's operation.
resolve(forwardingHandler[operation](o, ...args));
resolve(forwardingHandler[operation](o, ...args, returnedP));
})
.catch(reject);
};
Expand All @@ -473,7 +474,8 @@ export function makeHandledPromise(Promise) {
// We return a handled promise with the default unfulfilled handler.
// This prevents a race between the above Promise.resolves and
// pipelining.
return new HandledPromise(executor);
returnedP = new HandledPromise(executor);
return returnedP;
};

promiseResolve = Promise.resolve.bind(Promise);
Expand Down
8 changes: 4 additions & 4 deletions packages/eventual-send/test/test-hp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ test('chained properties', async t => {
const data = {};
const queue = [];
const handler = {
applyMethod(_o, prop, args) {
applyMethod(_o, prop, args, target) {
// Support: o~.[prop](...args) remote method invocation
queue.push([0, prop, args]);
queue.push([0, prop, args, target]);
return data;
// return queueMessage(slot, prop, args);
},
Expand All @@ -33,8 +33,8 @@ test('chained properties', async t => {
t.deepEqual(
queue,
[
[0, 'cont0', []],
[0, 'cont1', []],
[0, 'cont0', [], hp],
[0, 'cont1', [], hp],
],
`first turn`,
);
Expand Down

0 comments on commit 1f83d99

Please sign in to comment.