Skip to content

Commit

Permalink
Add AnonymouseDisposable
Browse files Browse the repository at this point in the history
  • Loading branch information
lempiji committed Jan 27, 2016
1 parent ed8863f commit 5a6933f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions source/rx/disposable.d
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,36 @@ unittest
auto d = new CompositeDisposable(d1, d2);
d.dispose();
}

class AnonymouseDisposable : Disposable
{
public:
this(void delegate() dispose)
{
assert(dispose !is null);
_dispose = dispose;
}

public:
void dispose()
{
if (_dispose !is null)
{
_dispose();
_dispose = null;
}
}

private:
void delegate() _dispose;
}
unittest
{
int count = 0;
auto d = new AnonymouseDisposable({ count++; });
assert(count == 0);
d.dispose();
assert(count == 1);
d.dispose();
assert(count == 1);
}

0 comments on commit 5a6933f

Please sign in to comment.