summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/webchannel/shared/qwebchannel.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/webchannel/shared/qwebchannel.js b/examples/webchannel/shared/qwebchannel.js
index 6cc3690..fca45d9 100644
--- a/examples/webchannel/shared/qwebchannel.js
+++ b/examples/webchannel/shared/qwebchannel.js
@@ -346,6 +346,7 @@ function QObject(name, data, webChannel)
object[methodName] = function() {
var args = [];
var callback;
+ var errCallback;
for (var i = 0; i < arguments.length; ++i) {
var argument = arguments[i];
if (typeof argument === "function")
@@ -358,6 +359,17 @@ function QObject(name, data, webChannel)
args.push(argument);
}
+ var result;
+ // during test, webChannel.exec synchronously calls the callback
+ // therefore, the promise must be constucted before calling
+ // webChannel.exec to ensure the callback is set up
+ if (!callback && (typeof(Promise) === 'function')) {
+ result = new Promise(function(resolve, reject) {
+ callback = resolve;
+ errCallback = reject;
+ });
+ }
+
webChannel.exec({
"type": QWebChannelMessageTypes.invokeMethod,
"object": object.__id__,
@@ -369,8 +381,12 @@ function QObject(name, data, webChannel)
if (callback) {
(callback)(result);
}
+ } else if (errCallback) {
+ (errCallback)();
}
});
+
+ return result;
};
}