1
- using AsyncFiberWorks . Core ;
2
1
using System ;
3
2
4
3
namespace AsyncFiberWorks . Channels
5
4
{
6
5
/// <summary>
7
6
/// Disposables.
8
7
/// </summary>
9
- public class Unsubscriber : ISubscriptionRegistry , IDisposable
8
+ public class Unsubscriber : IDisposable
10
9
{
11
10
private readonly object _lock = new object ( ) ;
12
11
private Action _actionUnsubscribe ;
@@ -33,52 +32,28 @@ public Unsubscriber(Action action)
33
32
/// <summary>
34
33
/// Add a disposable.
35
34
/// </summary>
36
- /// <param name="action"> </param>
37
- public void Add ( Action action )
35
+ /// <param name="disposingAction">A disposable. </param>
36
+ public void Add ( Action disposingAction )
38
37
{
39
38
bool added = false ;
40
39
lock ( _lock )
41
40
{
42
41
if ( ! _disposed )
43
42
{
44
- _actionUnsubscribe += action ;
43
+ _actionUnsubscribe += disposingAction ;
45
44
added = true ;
46
45
}
47
46
}
48
47
if ( ! added )
49
48
{
50
- action ( ) ;
49
+ disposingAction ( ) ;
51
50
}
52
51
}
53
52
54
53
/// <summary>
55
- /// Create and register a new Unsubscriber.
56
- /// It will be disposed when the subscription target ends.
54
+ /// Add a disposable.
57
55
/// </summary>
58
- /// <returns>Created unsubscriber.</returns>
59
- public Unsubscriber BeginSubscription ( )
60
- {
61
- var unsubscriber = new Unsubscriber ( ) ;
62
- Action action = ( ) => unsubscriber . Dispose ( ) ;
63
- this . Add ( action ) ;
64
- Action disposable = ( ) => this . Remove ( action ) ;
65
- unsubscriber . Add ( disposable ) ;
66
- return unsubscriber ;
67
- }
68
-
69
- private bool Remove ( Action action )
70
- {
71
- lock ( _lock )
72
- {
73
- if ( ! _disposed )
74
- {
75
- _actionUnsubscribe -= action ;
76
- return true ;
77
- }
78
- }
79
- return false ;
80
- }
81
-
56
+ /// <param name="disposable">A disposable.</param>
82
57
public void AddDisposable ( IDisposable disposable )
83
58
{
84
59
this . Add ( ( ) => disposable . Dispose ( ) ) ;
0 commit comments