summaryrefslogtreecommitdiff
path: root/gee/lightmapfuture.vala
blob: 86daf5ebb5c0ffaaed8b4f1753b29bd2438bad0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* lightmapfuture.vala
 *
 * Copyright (C) 2013  Maciej Piechotka
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Maciej Piechotka <uzytkownik2@gmail.com>
 */
internal class Gee.LightMapFuture<A, G> : Object, Future<A> {
	public LightMapFuture (Future<G> base_future, owned Future.LightMapFunc<A, G> func) {
		_base = base_future;
		_func = (owned)func;
	}

	public bool ready {
		get {
			return _base.ready;
		}
	}

	public GLib.Error exception {
		get {
			return _base.exception;
		}
	}

	public unowned A wait () throws Gee.FutureError {
		return _func (_base.wait ());
	}

	public bool wait_until (int64 end_time, out unowned G? value = null) throws Gee.FutureError {
		unowned A arg;
		bool result;
		value = null;
		if ((result = _base.wait_until (end_time, out arg))) {
			value = _func (arg);
		}
		return result;
	}

	public async unowned G wait_async () throws Gee.FutureError {
		unowned A arg = yield _base.wait_async ();
		return _func (arg);
	}

	private Future<G> _base;
	private Future.LightMapFunc<A, G> _func;
}