@@ -40,7 +40,7 @@ - (void)activateWithChannel:(id<RMQChannel>)channel
40
40
41
41
- (void )blockingWaitOn : (Class )method {
42
42
[self .commandQueue blockingEnqueue: ^{
43
- [self handleClosure: ^{
43
+ [self handleClosure: nil operation: ^{
44
44
[self .commandQueue suspend ];
45
45
}];
46
46
}];
@@ -56,8 +56,8 @@ - (void)blockingWaitOn:(Class)method {
56
56
- (void )sendSyncMethod : (id <RMQMethod>)method
57
57
completionHandler : (void (^)(RMQFramesetValidationResult *result))completionHandler {
58
58
[self .commandQueue enqueue: ^{
59
- [self handleClosure: ^{
60
- if ([method isKindOfClass: [RMQChannelClose class ] ]) {
59
+ [self handleClosure: method operation: ^{
60
+ if ([self isClose: method ]) {
61
61
self.state = DispatcherStateClosedByClient;
62
62
}
63
63
@@ -85,7 +85,7 @@ - (void)sendSyncMethod:(id<RMQMethod>)method {
85
85
86
86
- (void )sendSyncMethodBlocking : (id <RMQMethod>)method {
87
87
[self .commandQueue blockingEnqueue: ^{
88
- [self handleClosure: ^{
88
+ [self handleClosure: method operation: ^{
89
89
RMQFrameset *frameset = [[RMQFrameset alloc ] initWithChannelNumber: self .channelNumber method: method];
90
90
[self .commandQueue suspend ];
91
91
[self .sender sendFrameset: frameset];
@@ -94,15 +94,15 @@ - (void)sendSyncMethodBlocking:(id<RMQMethod>)method {
94
94
95
95
[self .commandQueue blockingEnqueue: ^{
96
96
RMQFramesetValidationResult *result = [self .validator expect: method.syncResponse];
97
- if (result.error ) {
97
+ if (self. state == DispatcherStateOpen && result.error ) {
98
98
[self .delegate channel: self .channel error: result.error];
99
99
}
100
100
}];
101
101
}
102
102
103
103
- (void )sendAsyncFrameset : (RMQFrameset *)frameset {
104
104
[self .commandQueue enqueue: ^{
105
- [self handleClosure: ^{
105
+ [self handleClosure: frameset.method operation: ^{
106
106
[self .sender sendFrameset: frameset];
107
107
}];
108
108
}];
@@ -113,7 +113,7 @@ - (void)sendAsyncMethod:(id<RMQMethod>)method {
113
113
}
114
114
115
115
- (void )handleFrameset : (RMQFrameset *)frameset {
116
- if (self.state != DispatcherStateClosedByServer && [frameset.method isKindOfClass: [RMQChannelClose class ] ]) {
116
+ if (self.state != DispatcherStateClosedByServer && [self isClose: frameset.method]) {
117
117
self.state = DispatcherStateClosedByServer;
118
118
[self .sender sendFrameset: [[RMQFrameset alloc ] initWithChannelNumber: self .channelNumber
119
119
method: [RMQChannelCloseOk new ]]];
@@ -129,11 +129,12 @@ - (NSNumber *)channelNumber {
129
129
return self.channel .channelNumber ;
130
130
}
131
131
132
- - (void )handleClosure : (void (^)())operation {
133
- if (self.state != DispatcherStateOpen) {
134
- [self sendChannelClosedError ];
135
- } else {
132
+ - (void )handleClosure : (id <RMQMethod>)method
133
+ operation : (void (^)())operation {
134
+ if (self.state == DispatcherStateOpen) {
136
135
operation ();
136
+ } else if (![self isClose: method]) {
137
+ [self sendChannelClosedError ];
137
138
}
138
139
}
139
140
@@ -144,4 +145,8 @@ - (void)sendChannelClosedError {
144
145
[self .delegate channel: self .channel error: error];
145
146
}
146
147
148
+ - (BOOL )isClose : (id <RMQMethod>)method {
149
+ return [method isKindOfClass: [RMQChannelClose class ]];
150
+ }
151
+
147
152
@end
0 commit comments