.
1 /*
2 Copyright (C) 2014 2015 Johan Mattsson
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 3 of the
7 License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13 */
14
15 namespace BirdFont {
16
17 public class Task : GLib.Object {
18
19 public delegate void Runnable ();
20 Runnable task;
21 bool cancelled = false;
22
23 public Task (owned Runnable? r) {
24 if (r != null) {
25 task = (!) ((owned) r);
26 }
27 }
28
29 public void cancel () {
30 lock (cancelled) {
31 cancelled = true;
32 }
33 }
34
35 public bool is_cancelled () {
36 bool c;
37
38 lock (cancelled) {
39 c = cancelled;
40 }
41
42 return c;
43 }
44
45 public virtual void run () {
46 if (task == null) {
47 warning ("No task set.");
48 return;
49 }
50
51 task ();
52 }
53
54 public void* perform_task() {
55 run ();
56 return null;
57 }
58 }
59
60 }
61