1 contributor
32 lines913 bytes
1#ifndef FUTURE_H
2#define FUTURE_H
3#include <stdbool.h>
4
5typedef struct Future Future;
6
7
8typedef struct Future_vfptrs_t {
9 void (*dtor)(Future *);
10 void (*await)(Future *);
11 void (*set_result)(Future *, bool, void *);
12} Future_vfptrs_t;
13
14void _Future_Await(Future *fut);
15void _Future_SetResult(Future *fut, bool canceled, void *res);
16
17// Notified when a Future is done (has a result or is canceled)
18typedef void (*Future_Watcher)(void *me, Future *fut);
19
20void Future_ctor(Future *fut);
21Future *Future_New();
22void Future_dtor(Future *fut);
23void Future_Delete(Future *fut);
24void Future_SetResult(Future *fut, bool canceled, void *value);
25bool Future_GetResult(Future *fut, void **res);
26void Future_AddWatcher(Future *fut, Future_Watcher watcher, void *me);
27void Future_RemoveWatcher(Future *fut, Future_Watcher watcher, void *me);
28bool Future_Await(Future *fut, void **res);
29
30#include "future.def.h"
31#endif
32