File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ extension ReplaySubject {
137
137
138
138
func forwardCompletionToBuffer( _ completion: Subscribers . Completion < Failure > ) {
139
139
demandBuffer? . complete ( completion: completion)
140
+ cancel ( )
140
141
}
141
142
142
143
func request( _ demand: Subscribers . Demand ) {
Original file line number Diff line number Diff line change @@ -213,5 +213,33 @@ final class ShareReplayTests: XCTestCase {
213
213
XCTAssertTrue ( results. isEmpty)
214
214
XCTAssertEqual ( completions, [ . failure( . someError) ] )
215
215
}
216
+
217
+ func testSharingDoesNotRetainClassBasedPublisher( ) {
218
+ var results = [ Int] ( )
219
+ var completions = [ Subscribers . Completion < Never > ] ( )
220
+
221
+ var source : PassthroughSubject ? = PassthroughSubject < Int , Never > ( )
222
+ weak var weakSource = source
223
+
224
+ var stream = source? . share ( replay: 1 )
225
+
226
+ stream?
227
+ . sink (
228
+ receiveCompletion: { completions. append ( $0) } ,
229
+ receiveValue: { results. append ( $0) }
230
+ )
231
+ . store ( in: & subscriptions)
232
+
233
+ source? . send ( 1 )
234
+ source? . send ( completion: . finished)
235
+
236
+ subscriptions. forEach ( { $0. cancel ( ) } )
237
+ stream = nil
238
+ source = nil
239
+
240
+ XCTAssertEqual ( results, [ 1 ] )
241
+ XCTAssertEqual ( completions, [ . finished] )
242
+ XCTAssertNil ( weakSource)
243
+ }
216
244
}
217
245
#endif
You can’t perform that action at this time.
0 commit comments