Allow using async functions as signal handlers
Using an async function as a signal handler works, but logs a (mostly harmless) warning.
Here's a minimal script to illustrate the problem:
const {GObject} = imports.gi;
const MyClass = GObject.registerClass({
Signals: {
signal: {},
},
}, class MyClass extends GObject.Object {
go() {
this.emit('signal');
}
});
const obj = new MyClass();
obj.connect('signal', async function (obj) {});
obj.go();
This prints:
(gjs:340): Gjs-WARNING **: 16:11:40.962: JS ERROR: Error: Could not guess unspecified GValue type
go@bug.js:9:9
@bug.js:15:1
although it does execute normally.
It's because the async function returns a Promise under the hood, which GJS tries to convert to the signal's return type of GObject.TYPE_NONE
, which causes the warning. (If you comment out the async
keyword, everything works normally.)
I think we should detect this particular case (signal with "none" return type, handler returns a Promise) and silently discard the return value, which would allow async functions to be used as handlers for signals that don't expect a return value. The Promise will just continue executing and eventually reach any code after an await
expression in the handler.
We should not allow this for signals with return types, because an async function can only return a Promise, and not any other return type that the signal expects.