MainLoop loop; public class CommandBundle { public SourceFunc callback; } public class Test { GLib.Queue q; uint watch; public Test() { q = new GLib.Queue(); } public async void enqueue() { if (q.length == 0) watch = Idle.add( processQueue ); message( "callback = %p", (void*)enqueue.callback ); CommandBundle bundle = new CommandBundle() { callback=enqueue.callback }; message( "callback = %p", (void*)bundle.callback ); assert( enqueue.callback == bundle.callback ); q.push_tail( bundle ); } public bool processQueue() { var bundle = q.pop_head(); var empty = q.length == 0; if (empty && watch > 0) { Source.remove( watch ); watch = 0; return false; // don't call again } return true; // call me again } } void main() { loop = new MainLoop( null, false ); var t = new Test(); t.enqueue(); loop.run(); }