Reactive Extensions: AnonymousDisposable

When you subscribe to a channel in Retlang, you get an IUnsubscriber back.  The equivalent of this in Rx is just IDisposable.  This makes AnonymousDisposable is a fairly vital class in ReactiveExtensions. I even used it in the last post. It’s a pity someone decided to mark it as internal (again).  So here’s another implementation of it:

public class AnonymousDisposable : IDisposable
{
    private readonly Action _onDispose;

    public AnonymousDisposable(Action onDispose)
    {
        _onDispose = onDispose;
    }

    public void Dispose()
    {
        _onDispose();
    }
}

Published by

Julian Birch

Full time dad, does a bit of coding on the side.

One thought on “Reactive Extensions: AnonymousDisposable”

  1. *clank* You’re right. The same holds true of AnonymousObserver. I’m still not very impressed with Microsoft’s love affair with static methods, though. It feels like unnecessary code hiding to me. And I note that, in their own code, they don’t call Disposable.Create.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s