UniRx 에셋 추가
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace UniRx
|
||||
{
|
||||
public sealed class MultipleAssignmentDisposable : IDisposable, ICancelable
|
||||
{
|
||||
static readonly BooleanDisposable True = new BooleanDisposable(true);
|
||||
|
||||
object gate = new object();
|
||||
IDisposable current;
|
||||
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
return current == True;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IDisposable Disposable
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
return (current == True)
|
||||
? UniRx.Disposable.Empty
|
||||
: current;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
var shouldDispose = false;
|
||||
lock (gate)
|
||||
{
|
||||
shouldDispose = (current == True);
|
||||
if (!shouldDispose)
|
||||
{
|
||||
current = value;
|
||||
}
|
||||
}
|
||||
if (shouldDispose && value != null)
|
||||
{
|
||||
value.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
IDisposable old = null;
|
||||
|
||||
lock (gate)
|
||||
{
|
||||
if (current != True)
|
||||
{
|
||||
old = current;
|
||||
current = True;
|
||||
}
|
||||
}
|
||||
|
||||
if (old != null) old.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user