Skip to content

Commit 6e4124c

Browse files
authored
fix(core): remove AmplifyOperation unsubscribe function (#2455)
1 parent 18eb5aa commit 6e4124c

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

Amplify/Core/Support/AmplifyOperation.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ open class AmplifyOperation<Request: AmplifyOperationRequest, Success, Failure:
143143
return token!
144144
}
145145

146-
func unsubscribe(token: UnsubscribeToken) {
147-
guard let token = resultListenerUnsubscribeToken else { return }
148-
Amplify.Hub.removeListener(token)
149-
resultListenerUnsubscribeToken = nil
150-
}
151-
152146
/// Classes that override this method must emit a completion to the `resultPublisher` upon cancellation
153147
open override func cancel() {
154148
super.cancel()
@@ -160,10 +154,7 @@ open class AmplifyOperation<Request: AmplifyOperationRequest, Success, Failure:
160154
)
161155
publish(result: .failure(cancellationError))
162156
#endif
163-
if let token = resultListenerUnsubscribeToken {
164-
unsubscribe(token: token)
165-
resultListenerUnsubscribeToken = nil
166-
}
157+
removeResultListener()
167158
}
168159

169160
/// Dispatches an event to the hub. Internally, creates an
@@ -188,7 +179,9 @@ open class AmplifyOperation<Request: AmplifyOperationRequest, Success, Failure:
188179
guard let unsubscribeToken = resultListenerUnsubscribeToken else {
189180
return
190181
}
182+
191183
Amplify.Hub.removeListener(unsubscribeToken)
184+
resultListenerUnsubscribeToken = nil
192185
}
193186

194187
}

AmplifyTests/CoreTests/AmplifyAsyncSequenceTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ final class AmplifyAsyncSequenceTests: XCTestCase {
212212
XCTAssertFalse(operation.isCancelled)
213213
XCTAssertGreaterThanOrEqual(count, steps)
214214

215-
operation.unsubscribe(token: token)
215+
Amplify.Hub.removeListener(token)
216216
}
217217

218218
func testCancellingWithParentOperation() async throws {
@@ -250,7 +250,7 @@ final class AmplifyAsyncSequenceTests: XCTestCase {
250250
XCTAssertTrue(operation.isCancelled)
251251
XCTAssertLessThan(count, steps)
252252

253-
operation.unsubscribe(token: token)
253+
Amplify.Hub.removeListener(token)
254254
}
255255

256256
func testThrowingValueProducingParentOperation() async throws {
@@ -288,7 +288,7 @@ final class AmplifyAsyncSequenceTests: XCTestCase {
288288
XCTAssertFalse(operation.isCancelled)
289289
XCTAssertGreaterThanOrEqual(count, steps)
290290

291-
operation.unsubscribe(token: token)
291+
Amplify.Hub.removeListener(token)
292292
}
293293

294294
func testThrowingCancellingWithParentOperation() async throws {
@@ -326,7 +326,7 @@ final class AmplifyAsyncSequenceTests: XCTestCase {
326326
XCTAssertTrue(operation.isCancelled)
327327
XCTAssertLessThan(count, steps)
328328

329-
operation.unsubscribe(token: token)
329+
Amplify.Hub.removeListener(token)
330330
}
331331

332332
private func send<Element>(elements: [Element], channel: AmplifyAsyncSequence<Element>, sleepSeconds: Double = 0.1) async throws {

0 commit comments

Comments
 (0)