interface Foo : GLib.Object { public signal void message_received (); public abstract async bool send_message (string message, Cancellable? cancellable = null); } // depending on the size of number the timeout will be there before everything is finished //public static const int NUMBER = 100000; public static const int NUMBER = 100000000; async void run () { Cancellable cancellable = new Cancellable(); uint timeout = 0; timeout = Timeout.add(2000, () => { // Timed out print("timed out\n"); cancellable.cancel(); timeout = 0; return false; // no repeat for the timeout }); bool result = yield _foo.send_message ("ping", cancellable); if(timeout != 0) { Source.remove(timeout); } if(result) print("success\n"); else print("no success\n"); } Foo _foo; class Test : GLib.Object, Foo { public async bool send_message (string message, Cancellable? cancellable = null) { //do something time consuming for(int i = 0; i { print("received\n"); }); run.begin (); var loop = new GLib.MainLoop (null, false); loop.run (); }