Inline the resolveOrReject
helper function at its call-sites in MessageHandler
, and rename an error
key to reason
Given that there's only a couple of call-sites, and that the helper function is really simple, it doesn't seem entirely necessary to keep it around. While fewer function calls is always a good thing, in this case the performance impact is small enough to be unmeasurable. With *one* single exception the code in `MessageHandler` is using `reason` when passing around various Errors, hence this patch also renames an `error` key for consistency.
This commit is contained in:
parent
0617984b59
commit
4bd79ec4b3
@ -48,14 +48,6 @@ function wrapReason(reason) {
|
||||
}
|
||||
}
|
||||
|
||||
function resolveOrReject(capability, data) {
|
||||
if (data.success) {
|
||||
capability.resolve();
|
||||
} else {
|
||||
capability.reject(wrapReason(data.reason));
|
||||
}
|
||||
}
|
||||
|
||||
function MessageHandler(sourceName, targetName, comObj) {
|
||||
this.sourceName = sourceName;
|
||||
this.targetName = targetName;
|
||||
@ -80,8 +72,8 @@ function MessageHandler(sourceName, targetName, comObj) {
|
||||
if (data.callbackId in callbacksCapabilities) {
|
||||
let callback = callbacksCapabilities[callbackId];
|
||||
delete callbacksCapabilities[callbackId];
|
||||
if ('error' in data) {
|
||||
callback.reject(wrapReason(data.error));
|
||||
if ('reason' in data) {
|
||||
callback.reject(wrapReason(data.reason));
|
||||
} else {
|
||||
callback.resolve(data.data);
|
||||
}
|
||||
@ -109,7 +101,7 @@ function MessageHandler(sourceName, targetName, comObj) {
|
||||
targetName,
|
||||
isReply: true,
|
||||
callbackId: data.callbackId,
|
||||
error: wrapReason(reason),
|
||||
reason: wrapReason(reason),
|
||||
});
|
||||
});
|
||||
} else if (data.streamId) {
|
||||
@ -358,10 +350,20 @@ MessageHandler.prototype = {
|
||||
|
||||
switch (data.stream) {
|
||||
case StreamKind.START_COMPLETE:
|
||||
resolveOrReject(this.streamControllers[streamId].startCall, data);
|
||||
if (data.success) {
|
||||
this.streamControllers[streamId].startCall.resolve();
|
||||
} else {
|
||||
this.streamControllers[streamId].startCall.reject(
|
||||
wrapReason(data.reason));
|
||||
}
|
||||
break;
|
||||
case StreamKind.PULL_COMPLETE:
|
||||
resolveOrReject(this.streamControllers[streamId].pullCall, data);
|
||||
if (data.success) {
|
||||
this.streamControllers[streamId].pullCall.resolve();
|
||||
} else {
|
||||
this.streamControllers[streamId].pullCall.reject(
|
||||
wrapReason(data.reason));
|
||||
}
|
||||
break;
|
||||
case StreamKind.PULL:
|
||||
// Ignore any pull after close is called.
|
||||
@ -431,7 +433,12 @@ MessageHandler.prototype = {
|
||||
deleteStreamController();
|
||||
break;
|
||||
case StreamKind.CANCEL_COMPLETE:
|
||||
resolveOrReject(this.streamControllers[streamId].cancelCall, data);
|
||||
if (data.success) {
|
||||
this.streamControllers[streamId].cancelCall.resolve();
|
||||
} else {
|
||||
this.streamControllers[streamId].cancelCall.reject(
|
||||
wrapReason(data.reason));
|
||||
}
|
||||
deleteStreamController();
|
||||
break;
|
||||
case StreamKind.CANCEL:
|
||||
|
Loading…
Reference in New Issue
Block a user