-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComposer1.h
68 lines (55 loc) · 1.83 KB
/
Composer1.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
66
67
68
#pragma once
#include"RxConcurrent/FutureFactory.h"
#include"RxConcurrent/ScheduledFutureTask.h"
#include"RxConcurrent/ThreadPool/ThreadPoolFactory.h"
#include"RxConcurrent/Export.h"
namespace BaseLib { namespace Concurrent {
class DLL_STATE ComposerBase
{
public:
virtual ~ComposerBase();
};
template <typename Return, typename Arg1>
class Composer1
: public ComposerBase
, public std::enable_shared_from_this<Composer1<Return, Arg1>>
{
public:
Composer1(std::function<Return(Arg1)> function)
: function_(std::make_shared<Templates::OperatorFunction1<Return, Arg1>>(function))
{ }
Composer1(std::shared_ptr<Templates::OperatorFunction1<Return, Arg1>> function)
: function_(function)
{ }
virtual ~Composer1()
{ }
template <typename Return1>
std::shared_ptr<Composer1<Return1, Arg1>> Then(std::function<Return1(Return)> after)
{
auto newComposer = std::make_shared<Composer1<Return1, Arg1>>(
function_->After(after)
);
composers_.push_back(newComposer);
return newComposer;
}
template <typename Arg2>
std::shared_ptr<Composer1<Arg1, Arg2>> Before(std::function<Arg1(Arg2)> before)
{
auto newComposer = std::make_shared<Composer1<Arg1, Arg2>>(
function_->Before(before)
);
composers_.push_back(newComposer);
return newComposer;
}
ScheduledFutureTask<Return> Execute(Arg1 arg1, TaskPolicy policy = TaskPolicy::RunOnceImmediately())
{
return ThreadPoolFactory::Instance().GetDefault()->Schedule<Return>(
FutureFactory::Create<Return, Arg1>(function_, arg1),
policy
);
}
private:
std::list<std::shared_ptr<ComposerBase>> composers_;
std::shared_ptr<Templates::OperatorFunction1<Return, Arg1>> function_;
};
}}