Skip to content

Commit

Permalink
[WIP] MessageHandler-resolveCall
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffleupagus committed Sep 1, 2019
1 parent 10165c0 commit 7c18b51
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/shared/message_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ const StreamKind = {
START_COMPLETE: 8,
};

async function resolveCall(fn, args) {
if (!fn) {
return undefined;
}
return fn.apply(null, args);
}

function wrapReason(reason) {
if (typeof reason !== 'object') {
return reason;
Expand Down Expand Up @@ -100,8 +93,8 @@ function MessageHandler(sourceName, targetName, comObj) {
if (data.callbackId) {
let sourceName = this.sourceName;
let targetName = data.sourceName;
Promise.resolve().then(function() {
return action(data.data);
new Promise(function(resolve) {
resolve(action(data.data));
}).then((result) => {
comObj.postMessage({
sourceName,
Expand Down Expand Up @@ -318,15 +311,17 @@ MessageHandler.prototype = {
streamSink.sinkCapability.resolve();
streamSink.ready = streamSink.sinkCapability.promise;
this.streamSinks[streamId] = streamSink;
resolveCall(action, [data.data, streamSink]).then(() => {
new Promise(function(resolve) {
resolve(action(data.data, streamSink));
}).then(function() {
comObj.postMessage({
sourceName,
targetName,
stream: StreamKind.START_COMPLETE,
streamId,
success: true,
});
}, (reason) => {
}, function(reason) {
comObj.postMessage({
sourceName,
targetName,
Expand Down Expand Up @@ -385,15 +380,18 @@ MessageHandler.prototype = {
}
// Reset desiredSize property of sink on every pull.
this.streamSinks[data.streamId].desiredSize = data.desiredSize;
resolveCall(this.streamSinks[data.streamId].onPull).then(() => {
const { onPull, } = this.streamSinks[data.streamId];
new Promise(function(resolve) {
resolve(onPull && onPull());
}).then(function() {
comObj.postMessage({
sourceName,
targetName,
stream: StreamKind.PULL_COMPLETE,
streamId,
success: true,
});
}, (reason) => {
}, function(reason) {
comObj.postMessage({
sourceName,
targetName,
Expand Down Expand Up @@ -435,16 +433,18 @@ MessageHandler.prototype = {
if (!this.streamSinks[data.streamId]) {
break;
}
resolveCall(this.streamSinks[data.streamId].onCancel,
[wrapReason(data.reason)]).then(() => {
const { onCancel, } = this.streamSinks[data.streamId];
new Promise(function(resolve) {
resolve(onCancel && onCancel(wrapReason(data.reason)));
}).then(function() {
comObj.postMessage({
sourceName,
targetName,
stream: StreamKind.CANCEL_COMPLETE,
streamId,
success: true,
});
}, (reason) => {
}, function(reason) {
comObj.postMessage({
sourceName,
targetName,
Expand Down

0 comments on commit 7c18b51

Please sign in to comment.