Reactive Extensions: AnonymousDisposable

03 August 2010 22:32

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();
    }
}

Comments
Gravatar
# re: Reactive Extensions: AnonymousDisposable
Posted by Omer Mor on 04/08/2010 20:46
There's no need to re-implement this class.
You can create an instance of it using the factory method Disposable.Create(action);
Gravatar
# re: Reactive Extensions: AnonymousDisposable
Posted by Julian on 04/08/2010 21:01
*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.
Something to add?

Talking sense? Talking rubbish? Something I'm missing? Let me know!

Fields denoted with a "*" are required.

 (will not be displayed)

 
Please add 1 and 4 and type the answer here:

Preview Your Comment