diff --git a/src/com/stuypulse/stuylib/streams/PollingIStream.java b/src/com/stuypulse/stuylib/streams/PollingIStream.java index 56e42512..37d02f6d 100644 --- a/src/com/stuypulse/stuylib/streams/PollingIStream.java +++ b/src/com/stuypulse/stuylib/streams/PollingIStream.java @@ -29,19 +29,23 @@ public PollingIStream(IStream stream, double dt) { } mResult = 0.0; - mPoller = new Notifier(() -> mResult = stream.get()); + mPoller = new Notifier(() -> this.set(stream.get())); mPoller.startPeriodic(dt); } - public double get() { + private final synchronized void set(double result) { + mResult = result; + } + + public final synchronized double get() { return mResult; } - protected void finalize() { + protected synchronized void finalize() { close(); } - public void close() { + public synchronized void close() { mPoller.close(); mResult = 0.0; } diff --git a/src/com/stuypulse/stuylib/streams/angles/PollingAStream.java b/src/com/stuypulse/stuylib/streams/angles/PollingAStream.java index feb1e258..6fa7acd6 100644 --- a/src/com/stuypulse/stuylib/streams/angles/PollingAStream.java +++ b/src/com/stuypulse/stuylib/streams/angles/PollingAStream.java @@ -31,19 +31,23 @@ public PollingAStream(AStream stream, double dt) { } mResult = Angle.kNull; - mPoller = new Notifier(() -> mResult = stream.get()); + mPoller = new Notifier(() -> this.set(stream.get())); mPoller.startPeriodic(dt); } - public Angle get() { + private final synchronized void set(Angle result) { + mResult = result; + } + + public final synchronized Angle get() { return mResult; } - protected void finalize() { + protected synchronized void finalize() { close(); } - public void close() { + public synchronized void close() { mPoller.close(); mResult = Angle.kNull; } diff --git a/src/com/stuypulse/stuylib/streams/booleans/PollingBStream.java b/src/com/stuypulse/stuylib/streams/booleans/PollingBStream.java index 805a5c5f..419b0028 100644 --- a/src/com/stuypulse/stuylib/streams/booleans/PollingBStream.java +++ b/src/com/stuypulse/stuylib/streams/booleans/PollingBStream.java @@ -31,19 +31,23 @@ public PollingBStream(BStream stream, double dt) { } mResult = false; - mPoller = new Notifier(() -> mResult = stream.get()); + mPoller = new Notifier(() -> this.set(stream.get())); mPoller.startPeriodic(dt); } - public boolean get() { + private final synchronized void set(boolean result) { + mResult = result; + } + + public final synchronized boolean get() { return mResult; } - protected void finalize() { + protected synchronized void finalize() { close(); } - public void close() { + public synchronized void close() { mPoller.close(); mResult = false; } diff --git a/src/com/stuypulse/stuylib/streams/vectors/PollingVStream.java b/src/com/stuypulse/stuylib/streams/vectors/PollingVStream.java index b015b9f7..c7736b01 100644 --- a/src/com/stuypulse/stuylib/streams/vectors/PollingVStream.java +++ b/src/com/stuypulse/stuylib/streams/vectors/PollingVStream.java @@ -31,19 +31,23 @@ public PollingVStream(VStream stream, double dt) { } mResult = Vector2D.kOrigin; - mPoller = new Notifier(() -> mResult = stream.get()); + mPoller = new Notifier(() -> this.set(stream.get())); mPoller.startPeriodic(dt); } - public Vector2D get() { + private final synchronized void set(Vector2D result) { + mResult = result; + } + + public final synchronized Vector2D get() { return mResult; } - protected void finalize() { + protected synchronized void finalize() { close(); } - public void close() { + public synchronized void close() { mPoller.close(); mResult = Vector2D.kOrigin; }