summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2022-03-29 03:51:17 +0000
committerPhilip Chimento <philip.chimento@gmail.com>2022-03-29 03:51:17 +0000
commit70552bee79f644836a5e9f9a54845791b1ef7a94 (patch)
treecd1ea7eb035e855560073c5a0e382b1a509ebd99
parent46c761e9196fc01fd6622196297a6446a5a999e3 (diff)
parent7087f0501141a3dbaa87caffebdaf67aa4ddc16d (diff)
downloadgjs-70552bee79f644836a5e9f9a54845791b1ef7a94.tar.gz
Merge branch 'add_async_dbus_methods' into 'master'
Add support for JS async calls in DBusProxyWrapper See merge request GNOME/gjs!731
-rw-r--r--installed-tests/js/testGDBus.js13
-rw-r--r--modules/core/overrides/Gio.js16
2 files changed, 28 insertions, 1 deletions
diff --git a/installed-tests/js/testGDBus.js b/installed-tests/js/testGDBus.js
index 78907e48..88c5831b 100644
--- a/installed-tests/js/testGDBus.js
+++ b/installed-tests/js/testGDBus.js
@@ -407,6 +407,19 @@ describe('Exported DBus object', function () {
loop.run();
});
+ async function testAsync(value) {
+ let result = await proxy.nonJsonFrobateStuffAsync(value);
+ return result;
+ }
+
+ it('can call a remote method using AWAIT', function () {
+ testAsync(1).then(result => {
+ expect(result[0]).toEqual('Oops');
+ loop.quit();
+ });
+ loop.run();
+ });
+
it('can call a remote method with no in parameter', function () {
proxy.noInParameterRemote(([result], excp) => {
expect(result).toEqual('Yes!');
diff --git a/modules/core/overrides/Gio.js b/modules/core/overrides/Gio.js
index be2e5247..6cc29b17 100644
--- a/modules/core/overrides/Gio.js
+++ b/modules/core/overrides/Gio.js
@@ -185,8 +185,22 @@ function _addDBusConvenience() {
let i, methods = info.methods;
for (i = 0; i < methods.length; i++) {
var method = methods[i];
- this[`${method.name}Remote`] = _makeProxyMethod(methods[i], false);
+ let remoteMethod = _makeProxyMethod(methods[i], false);
+ this[`${method.name}Remote`] = remoteMethod;
this[`${method.name}Sync`] = _makeProxyMethod(methods[i], true);
+ this[`${method.name}Async`] = function (...args) {
+ return new Promise((resolve, reject) => {
+ args.push((result, error, fdList) => {
+ if (error)
+ reject(error);
+ else if (fdList)
+ resolve([result, fdList]);
+ else
+ resolve(result);
+ });
+ remoteMethod.call(this, ...args);
+ });
+ };
}
let properties = info.properties;