aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/comm.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed/js/comm.js')
-rw-r--r--ext/mixed/js/comm.js33
1 files changed, 13 insertions, 20 deletions
diff --git a/ext/mixed/js/comm.js b/ext/mixed/js/comm.js
index 0d6b8695..182400e3 100644
--- a/ext/mixed/js/comm.js
+++ b/ext/mixed/js/comm.js
@@ -172,29 +172,22 @@ class CrossFrameAPIPort extends EventDispatcher {
return;
}
- const {handler, async} = messageHandler;
+ let {handler, async} = messageHandler;
this._sendAck(id);
- if (async) {
- this._invokeHandlerAsync(id, handler, params);
- } else {
- this._invokeHandler(id, handler, params);
- }
- }
-
- _invokeHandler(id, handler, params) {
- try {
- const result = handler(params);
- this._sendResult(id, result);
- } catch (error) {
- this._sendError(id, error);
- }
- }
-
- async _invokeHandlerAsync(id, handler, params) {
try {
- const result = await handler(params);
- this._sendResult(id, result);
+ let result = handler(params);
+ if (async === 'dynamic') {
+ ({async, result} = result);
+ }
+ if (async) {
+ result.then(
+ (result2) => this._sendResult(id, result2),
+ (error2) => this._sendError(id, error2)
+ );
+ } else {
+ this._sendResult(id, result);
+ }
} catch (error) {
this._sendError(id, error);
}