Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behaviour of Operational.value(...) in java version. #113

Closed
clinuxrulz opened this issue Oct 16, 2017 · 2 comments
Closed

Behaviour of Operational.value(...) in java version. #113

clinuxrulz opened this issue Oct 16, 2017 · 2 comments

Comments

@clinuxrulz
Copy link
Contributor

The following piece of code:

public static void main(String[] params) {
    System.out.println("First Test");
    {
        nz.sodium.CellSink<Integer> cs = new nz.sodium.CellSink<>(1);
        nz.sodium.Listener l = nz.sodium.Operational.value(cs).listen(System.out::println);
        for (int i = 2; i < 5; ++i) {
            cs.send(i);
        }
        l.unlisten();
    }
    System.out.println("Second Test");
    {
        nz.sodium.CellSink<Integer> cs = new nz.sodium.CellSink<>(1);
        nz.sodium.Listener l = cs.listen(System.out::println);
        for (int i = 2; i < 5; ++i) {
            cs.send(i);
        }
        l.unlisten();
    }
}

Outputed:

First Test
2
3
4
Second Test
1
2
3
4

I expected the first test to output the same values as the second test. Is above a miss-use of Operational.value, or is it a bug?

@the-real-blackh
Copy link

It's not a bug. The issue is that in the first test, value() and listen() are operating within different transactions. You can make it behave as you expect by wrapping them into a single transaction context using Transaction.run(...).

@clinuxrulz
Copy link
Contributor Author

OK. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants