SodiumFRP / sodium

Sodium - Functional Reactive Programming (FRP) Library for multiple languages
http://sodium.nz/
Other
848 stars 138 forks source link

Fix Nested Transaction.Post Ordering #152

Closed jam40jeff closed 6 years ago

jam40jeff commented 6 years ago

Nested Transaction.Post code should execute after all "top level" Transaction.Post code has executed.

Given the following block of code:

Cell<int> cell = Transaction.Run(() =>
{
    StreamSink<int> s = Stream.CreateSink<int>();
    Transaction.Post(() =>
    {
        s.Send(1);
        Transaction.Post(() => s.Send(3));
    });
    Transaction.Post(() => s.Send(2));
    return s.Hold(0);
});

int result = cell.Sample();

The value of result should be 3, but it currently is 2 due to the nested Transaction.Post code executing before the second top-level Transaction.Post code.

jam40jeff commented 6 years ago

Fixed by 81b4a7cdbaa909eb6b83cd1acea9cd68920101de.