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