Skip to content

Instantly share code, notes, and snippets.

@lucabrunox
Last active December 29, 2015 23:59
Show Gist options
  • Save lucabrunox/7746798 to your computer and use it in GitHub Desktop.
Save lucabrunox/7746798 to your computer and use it in GitHub Desktop.
public delegate G TaskFunc<G> () throws Error;
public async G run_in_thread<G> (owned TaskFunc<G> func) throws Error {
SourceFunc resume = run_in_thread.callback;
Error err = null;
G result = null;
new Thread<void*> (null, () => {
try {
result = func ();
} catch (Error e) {
err = e;
}
Idle.add ((owned) resume);
return null;
});
yield;
if (err != null) {
throw err;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment