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 |
|||||
7 months ago |
14 |
extern void _Future_Await(Future *fut); | |||
15 |
extern void _Future_SetResult(Future *fut, bool canceled, void *res); | ||||
8 months ago |
37 |
16 |
|||
17 |
// Notified when a Future is done (has a result or is canceled) | ||||
18 |
typedef void (*Future_Watcher)(void *me, Future *fut); | ||||
19 |
|||||
7 months ago |
20 |
extern void Future_ctor(Future *fut); | |||
7 months ago |
21 |
extern Future *Future_New(void); | |||
7 months ago |
22 |
extern void Future_dtor(Future *fut); | |||
23 |
extern void Future_Delete(Future *fut); | ||||
24 |
extern void Future_SetResult(Future *fut, bool canceled, void *value); | ||||
25 |
extern bool Future_GetResult(Future *fut, void **res); | ||||
26 |
extern void Future_AddWatcher(Future *fut, Future_Watcher watcher, void *me); | ||||
27 |
extern void Future_RemoveWatcher(Future *fut, Future_Watcher watcher, void *me); | ||||
28 |
extern bool Future_Await(Future *fut, void **res); | ||||
8 months ago |
37 |
29 |
|||
30 |
#include "future.def.h" | ||||
31 |
#endif | ||||
32 |