YarikTH / ureact

Functional reactive programming library for c++
Boost Software License 1.0
155 stars 10 forks source link

Try allow inputs and transactions from observer callbacks #118

Open YarikTH opened 1 year ago

YarikTH commented 1 year ago

Description

Note: inputs are: var_signal::set, var_signal::modify, event_stream::emit.

Currently observer callbacks can't add inputs, because transactions is still in progress and current input value are still used, so their modification can ruin propagation process.

Theoretically propagation can be improved to allow it, and maybe it is wanted because library usage would be limited otherwise.

Such feature can allow infinite or finite loops if observer callback touches inputs which it depends on.

YarikTH commented 1 year ago

One of the difficulties is that it turns out that it is necessary to allow changing inputs, although they have not yet been cleaned up after the last transaction. One of the more or less reasonable options for allowing changes to inputs from observers is enque_transaction. Sometimes lambdas of scheduled transactions will simply be inserted into the queue and it will be possible to execute them in a batch upon completion of the propagate. Problems are obtained only with observers. But if you somehow postpone their execution to the end and first copy the data that will go to the lambdas, then maybe something will work out. You may also have to duplicate all the input node data in order to modify future data, but leave the current data unchanged. Which, however, does not fit well with the purpose of introducing modify, since this cannot be done without copying.