34 lines918 bytes
Newer
Older
-
+
commited
{line.log.rev}
on
8 months ago
1
#ifndef GENERATOR_H
2
#define GENERATOR_H
8 months ago
3
#include "coroutine.h"
9 months ago
2
4
#include <stdbool.h>
5
8 months ago
6
typedef enum Generator_State {
7
Generator_Running,
8
Generator_Deleting,
9
Generator_Complete
10
} Generator_State;
11
12
typedef struct Generator {
13
Coroutine *coroutine;
14
Coroutine *caller;
15
void *(*start)(void *);
16
void *param;
17
Generator_State state;
18
} Generator;
19
20
void Generator_ctor(Generator *gen, void *(*start)(void *), void *param);
9 months ago
2
21
Generator *Generator_New(void *(*)(void *), void *);
8 months ago
22
void Generator_dtor(Generator *gen);
9 months ago
2
23
void Generator_Delete(Generator *);
24
25
// Returns true if generator yielded a value, false if generator is complete
26
// *value is set to generator's value (yield / return value from exit)
27
bool Generator_Next(Generator *, void **value);
28
29
// Yield a value from the generator
30
// Returns true if generator should continue, false for generator to exit PDQ
31
bool Generator_Yield(void *);
8 months ago
32
33
#endif
34