Consider adding `transaction::finish()` method
Closed this issue · 1 comments
YarikTH commented
Description
sodium.cxx provides transaction::close()
method, so transaction can be closed without closing the scope.
https://github.com/SodiumFRP/sodium-cxx/blob/0.11.0/tests/test_sodium.cpp#L620-L626
// NOTE! Currently this leaks memory.
void test_sodium::loop_cell()
{
stream_sink<int> ea;
transaction trans;
cell_loop<int> sum;
sum.loop(ea.snapshot(sum, [] (const int& x, const int& y) { return x+y; }).hold(0));
auto out = std::make_shared<vector<int>>();
auto unlisten = sum.value().listen([out] (const int& x) { out->push_back(x); });
trans.close();
ea.send(2);
ea.send(3);
ea.send(1);
unlisten();
CPPUNIT_ASSERT(vector<int>({ 0, 2, 5, 6 }) == *out);
CPPUNIT_ASSERT(sum.sample() == 6);
}
It allows to create new variables inside transaction and use it immediately after it finishes. I don't see obvious scenarios where it is obviously useful, but it is nice to have simple feature.
Currently ureact has two transaction methods - scoped transaction RAII class and do_transaction() function. Both work in the closed scope and require additional work to expose variables created inside to the caller.
YarikTH commented
Done