-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCoroutine.h
65 lines (52 loc) · 1.12 KB
/
Coroutine.h
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
63
64
65
#ifndef NORLIT_COROUTINE_COROUTINE_H
#define NORLIT_COROUTINE_COROUTINE_H
#include <functional>
#include <exception>
#include "context.h"
namespace norlit {
namespace coroutine {
class Coroutine {
public:
enum Status {
READY,
RUNNING,
SUSPENDED,
STOPPED
};
private:
struct Data;
private:
static Data* current_;
public:
static void* yield(void* ret = nullptr);
static void* yield_throw(std::exception_ptr ex);
static Coroutine current();
template<typename T>
static void* yield_throw(T t) {
return yield_throw(std::make_exception_ptr(std::move(t)));
}
private:
Data* data;
private:
Coroutine(Data*);
public:
Coroutine();
Coroutine(Coroutine&&) throw();
Coroutine(const Coroutine&);
Coroutine(std::function<void*(void*)> func);
~Coroutine();
void operator =(Coroutine&&) throw();
void operator =(const Coroutine&);
bool empty();
void stop(void* val = nullptr);
void* resume(void* val = nullptr);
void* throw_exception(std::exception_ptr ex);
Status status();
template<typename T>
void* throw_exception(T t) {
return throw_exception(std::make_exception_ptr(std::move(t)));
}
};
}
}
#endif