Last active
December 29, 2015 23:59
-
-
Save lucabrunox/7746798 to your computer and use it in GitHub Desktop.
This file contains 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
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