Created
December 31, 2021 05:57
-
-
Save benwaffle/831777ac5c8242e4dad5b43fbe5684b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env vala --pkg gio-2.0 | |
delegate void Func(); | |
struct Box { | |
Func f; | |
} | |
async void run (Func f) { | |
var dummy = new Object (); | |
var task = new Task (dummy, null, () => Idle.add (run.callback)); | |
Box boxed = { f }; | |
task.set_task_data ((void*)&boxed, null); | |
task.run_in_thread ((task, obj, data, cancel) => { | |
Box *b = (Box*) data; | |
b.f (); | |
task.return_pointer (null, null); | |
}); | |
yield; | |
} | |
void main() { | |
var loop = new GLib.MainLoop (); | |
print ("start\n"); | |
int i = 3; | |
run.begin (() => print (@"running - $i\n"), (obj, res) => { | |
run.end (res); | |
print ("done\n"); | |
loop.quit (); | |
}); | |
loop.run (); | |
print ("end\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment