Gnome Javascript:回调不';不适用于异步函数

Gnome Javascript:回调不';不适用于异步函数,javascript,sockets,asynchronous,gnome-shell,Javascript,Sockets,Asynchronous,Gnome Shell,我试图从网络套接字读取,以使用gnome扩展中的信息。为此,我使用了Gio socketclient。我能够从inputstream连接并读取synchrone。但是我在异步读取上失败了。我已在以下脚本中隔离了我的问题: #!/usr/bin/gjs const Gio = imports.gi.Gio; var doAsyncCallBack = function(gobject, async_res, user_data) { print("ASYNC test: doCall

我试图从网络套接字读取,以使用gnome扩展中的信息。为此,我使用了Gio socketclient。我能够从inputstream连接并读取synchrone。但是我在异步读取上失败了。我已在以下脚本中隔离了我的问题:

#!/usr/bin/gjs

const Gio = imports.gi.Gio;


var doAsyncCallBack = function(gobject, async_res, user_data) {
    print("ASYNC test: doCallBack");
    let lineout, charlength, error;
    [lineout, charlength, error] = gobject.read_upto_finish(async_res);
    print("ASYNC test: " + lineout + " (" + charlength + ")");
};


let sc = new Gio.SocketClient();
let scc = sc.connect_to_host("kodi", 9090, null);
let dis = new Gio.DataInputStream({ base_stream: scc.get_input_stream() });

//sync
print("sync test: started");
let valuestr, valueint;
[valuestr, valueint] = dis.read_upto("}" , -1,  null);
print("sync test: " + valuestr + " (" + valueint + ")");

//async
print("ASYNC test: started");
dis.read_upto_async("}" , -1,  0, null, doAsyncCallBack);

// keep in a loop.
print("(press [crtl-c] to end)");
while (0 == 0) {};
在我的示例中,永远不会调用“doAsyncCallBack”函数。synchrone调用起作用,因此服务器将提供propper响应


我在这里找到了一部分信息,但是(kodi)服务器没有发送新行:

我找到了回调在脚本中不起作用的原因。基本上这是代码的最后一部分

// while (0 == 0) {};
Clutter.init(null);
Clutter.main();
这就是我必须做的,让它发挥作用