-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKRunnable.h
60 lines (58 loc) · 1.34 KB
/
KRunnable.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
#pragma once
#include<functional>
#include <mutex>
#include <windows.h>
#define ON_K_EVENT (WM_USER|0X5224)
#define RUN_MAIN(X) (new KRunnable([=] {X}))->runTask();
LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
void createMessageWindow();
class KFuture {
std::timed_mutex waitlock;
public:
KFuture();
virtual void start();
virtual void complete();
virtual bool wait(long time);
virtual void wait();
virtual bool isCompleted();
virtual void fail();
};
class KRunnable
{
private:
bool is_running = false;
KFuture* future= 0;
protected:
void Start() {
is_running = true;
if (future)
future->start();
}
void End() {
is_running = false;
if (future)
future->complete();
}
void Fail() {
is_running = false;
if (future)
future->fail();
}
public:
bool is_timer = false;
typedef std::function<void()> Runnable;
Runnable run;
KRunnable(Runnable func);
KRunnable(Runnable func,KFuture * future);
KRunnable* runTask();
KRunnable* runTaskLater(long time);
KRunnable* runTaskAsync();
KRunnable* runTaskLaterAsync(long time);
KRunnable* runTaskTimer(long first, long interval);
KRunnable* runTaskTimerAsync(long first, long interval);
KRunnable* cancelTimer();
bool isRunning();
bool setFuture(KFuture* future);
KFuture* getFuture();
friend LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
};