Skip to content

Commit a63a870

Browse files
committed
set run_forver (keepalive) automatically if there are input actions
1 parent d590c81 commit a63a870

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

examples/count/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Count : public Reactor {
3737
};
3838

3939
auto main() -> int {
40-
Environment env{4, true};
40+
Environment env{4};
4141

4242
Count count{&env};
4343
env.assemble();

examples/hello/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Hello : public Reactor {
3131
};
3232

3333
auto main() -> int {
34-
Environment env{4, false, false, 5s};
34+
Environment env{4, false, 5s};
3535

3636
Hello hello{&env};
3737
env.assemble();

include/reactor-cpp/environment.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private:
3737
const log::NamedLogger log_;
3838
const unsigned int num_workers_{default_number_worker};
3939
unsigned int max_reaction_index_{default_max_reaction_index};
40-
const bool run_forever_{default_run_forever};
40+
bool run_forever_{default_run_forever};
4141
const bool fast_fwd_execution_{default_fast_fwd_execution};
4242

4343
std::set<Reactor*> top_level_reactors_{};
@@ -67,8 +67,8 @@ private:
6767
auto startup(const TimePoint& start_time) -> std::thread;
6868

6969
public:
70-
explicit Environment(unsigned int num_workers, bool run_forever = default_run_forever,
71-
bool fast_fwd_execution = default_fast_fwd_execution, const Duration& timeout = Duration::max());
70+
explicit Environment(unsigned int num_workers, bool fast_fwd_execution = default_fast_fwd_execution,
71+
const Duration& timeout = Duration::max());
7272
explicit Environment(const std::string& name, Environment* containing_environment);
7373

7474
auto name() -> const std::string& { return name_; }

lib/environment.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323

2424
namespace reactor {
2525

26-
Environment::Environment(unsigned int num_workers, bool run_forever, bool fast_fwd_execution, const Duration& timeout)
26+
Environment::Environment(unsigned int num_workers, bool fast_fwd_execution, const Duration& timeout)
2727
: log_("Environment")
2828
, num_workers_(num_workers)
29-
, run_forever_(run_forever)
3029
, fast_fwd_execution_(fast_fwd_execution)
3130
, top_environment_(this)
3231
, scheduler_(this)
@@ -36,7 +35,6 @@ Environment::Environment(const std::string& name, Environment* containing_enviro
3635
: name_(name)
3736
, log_("Environment " + name)
3837
, num_workers_(containing_environment->num_workers_)
39-
, run_forever_(containing_environment->run_forever_)
4038
, fast_fwd_execution_(containing_environment->fast_fwd_execution_)
4139
, containing_environment_(containing_environment)
4240
, top_environment_(containing_environment_->top_environment_)
@@ -56,6 +54,7 @@ void Environment::register_input_action(BaseAction* action) {
5654
reactor_assert(action != nullptr);
5755
validate(this->phase() == Phase::Construction, "Input actions may only be registered during construction phase!");
5856
reactor_assert(input_actions_.insert(action).second);
57+
run_forever_ = true;
5958
}
6059

6160
void recursive_assemble(Reactor* container) { // NOLINT

0 commit comments

Comments
 (0)