Skip to content

Commit

Permalink
Merge pull request neuecc#248 from JoshuaLight/start-shrink-timer-tak…
Browse files Browse the repository at this point in the history
…ewhile-fix

Fixed bug, caused by boolean typo in `ObjectPool.StartShrinkTimer`.
  • Loading branch information
neuecc authored Jul 16, 2018
2 parents 3985775 + 7efb8f0 commit b9409b5
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions UnityEngineBridge/Toolkit/ObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace UniRx.Toolkit
public abstract class ObjectPool<T> : IDisposable
where T : UnityEngine.Component
{
bool disposedValue = false;
bool isDisposed = false;
Queue<T> q;

/// <summary>
Expand Down Expand Up @@ -77,7 +77,7 @@ public int Count
/// </summary>
public T Rent()
{
if (disposedValue) throw new ObjectDisposedException("ObjectPool was already disposed.");
if (isDisposed) throw new ObjectDisposedException("ObjectPool was already disposed.");
if (q == null) q = new Queue<T>();

var instance = (q.Count > 0)
Expand All @@ -93,7 +93,7 @@ public T Rent()
/// </summary>
public void Return(T instance)
{
if (disposedValue) throw new ObjectDisposedException("ObjectPool was already disposed.");
if (isDisposed) throw new ObjectDisposedException("ObjectPool was already disposed.");
if (instance == null) throw new ArgumentNullException("instance");

if (q == null) q = new Queue<T>();
Expand Down Expand Up @@ -161,7 +161,7 @@ public void Shrink(float instanceCountRatio, int minSize, bool callOnBeforeRent
public IDisposable StartShrinkTimer(TimeSpan checkInterval, float instanceCountRatio, int minSize, bool callOnBeforeRent = false)
{
return Observable.Interval(checkInterval)
.TakeWhile(_ => disposedValue)
.TakeWhile(_ => !isDisposed)
.Subscribe(_ =>
{
Shrink(instanceCountRatio, minSize, callOnBeforeRent);
Expand Down Expand Up @@ -213,14 +213,14 @@ IEnumerator PreloadCore(int preloadCount, int threshold, IObserver<Unit> observe

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
if (!isDisposed)
{
if (disposing)
{
Clear(false);
}

disposedValue = true;
isDisposed = true;
}
}

Expand All @@ -238,7 +238,7 @@ public void Dispose()
public abstract class AsyncObjectPool<T> : IDisposable
where T : UnityEngine.Component
{
bool disposedValue = false;
bool isDisposed = false;
Queue<T> q;

/// <summary>
Expand Down Expand Up @@ -302,7 +302,7 @@ public int Count
/// </summary>
public IObservable<T> RentAsync()
{
if (disposedValue) throw new ObjectDisposedException("ObjectPool was already disposed.");
if (isDisposed) throw new ObjectDisposedException("ObjectPool was already disposed.");
if (q == null) q = new Queue<T>();

if (q.Count > 0)
Expand All @@ -323,7 +323,7 @@ public IObservable<T> RentAsync()
/// </summary>
public void Return(T instance)
{
if (disposedValue) throw new ObjectDisposedException("ObjectPool was already disposed.");
if (isDisposed) throw new ObjectDisposedException("ObjectPool was already disposed.");
if (instance == null) throw new ArgumentNullException("instance");

if (q == null) q = new Queue<T>();
Expand Down Expand Up @@ -374,7 +374,7 @@ public void Shrink(float instanceCountRatio, int minSize, bool callOnBeforeRent
public IDisposable StartShrinkTimer(TimeSpan checkInterval, float instanceCountRatio, int minSize, bool callOnBeforeRent = false)
{
return Observable.Interval(checkInterval)
.TakeWhile(_ => disposedValue)
.TakeWhile(_ => !isDisposed)
.Subscribe(_ =>
{
Shrink(instanceCountRatio, minSize, callOnBeforeRent);
Expand Down Expand Up @@ -451,14 +451,14 @@ IEnumerator PreloadCore(int preloadCount, int threshold, IObserver<Unit> observe

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
if (!isDisposed)
{
if (disposing)
{
Clear(false);
}

disposedValue = true;
isDisposed = true;
}
}

Expand Down

0 comments on commit b9409b5

Please sign in to comment.