Add in post callback function to simulation#18
Conversation
|
I'm unsure whether this helps readability. As far as I understand it, both snippets should behave the same: sim.post([&ran]() { ran = true; }, 2.0);auto ev = sim.timeout(2.0);
ev.add_callback([&ran]() { ran = true; });Personally, I think the second version is readable, while you need to know the What is the use case for having this special post function? |
Correct, no difference.
There was no specific use case for this, more so we are using the same pattern repeatedly in multiple codebases of ours that it made sense to introduce a convenience one-liner function for it: void Callbacks_t::StartBitTimerInternal()
{
m_bitTimer = m_simulationContext.post(
[this]()
{
...
StartBitTimerInternal();
},
m_bitTimerPeriod.count());
}The post name comes from Boost::ASIO, but the functionality is similar to other event loop based frameworks. For example: python. Maybe a change to the name like python would work? |
This PR adds in
simulation<>::post()intended as a convenience method for creating an event with callback added, plus scheduling it to run immediately.Tests included and passing.