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

BehaviorSubject concurrent use in BattleFrontFeed.java #10

Open
akarnokd opened this issue Mar 13, 2018 · 1 comment
Open

BehaviorSubject concurrent use in BattleFrontFeed.java #10

akarnokd opened this issue Mar 13, 2018 · 1 comment

Comments

@akarnokd
Copy link

Hi!

I was watching the video of this code base and saw a common mistake in using Subjects:

private BehaviorSubject<Battle> battleSubject = BehaviorSubject.create();

Subjects by default are not thread safe when calling onNext and lines 34:

.delay(EMIT_RATE_SECONDS / 2, TimeUnit.SECONDS)
.subscribe(battle -> battleSubject.onNext(battle));

and 46:

observable.subscribe(battle -> battleSubject.onNext(battle));

may end up calling it concurrently, which leads to undefined behavior.

Line 26 should look like this instead:

private Subject<Battle> battleSubject = BehaviorSubject.<Battle>create().toSerialized(); 
@aderington
Copy link
Collaborator

Hi David,

Thank you so much for pointing this out! We really appreciate you looking over our samples and helping us to improve them (plus we got to learn more about concurrency with Subjects.)

We'll get the examples updated as soon as possible.

Cheers!
Angella Derington

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