Advertisement
Guest User

minimal example

a guest
Aug 12th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 0.71 KB | None | 0 0
  1. delegate void asyncPayload();
  2.  
  3. async void callAsync(asyncPayload func)
  4. {
  5.     SourceFunc callback = callAsync.callback;
  6.     ThreadFunc<void*> run = () => {
  7.         func();
  8.         Idle.add((owned) callback);
  9.         return null;
  10.     };
  11.  
  12.     new GLib.Thread<void*>("callAsync", run);
  13.     yield;
  14. }
  15.  
  16. void testFunc(int arg1, string arg2)
  17. {
  18.     stdout.printf("arg1: %i\n", arg1);
  19.     stdout.printf("arg2: %s\n", arg2);
  20. }
  21.  
  22. void main()
  23. {
  24.     int testInt = 5;
  25.     string testString = "test-string";
  26.  
  27.     asyncPayload pl = () => {
  28.         testFunc(testInt, testString);
  29.     };
  30.     callAsync.begin(pl, (obj, res) => { callAsync.end(res); });
  31.  
  32.     var loop = new MainLoop(null, false);
  33.     loop.run();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement