File tree Expand file tree Collapse file tree 4 files changed +38
-2
lines changed
main/scala/fs2/concurrent
test/scala/fs2/concurrent Expand file tree Collapse file tree 4 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,7 @@ object Channel {
151
151
new Channel [F , A ] {
152
152
153
153
def sendAll : Pipe [F , A , Nothing ] = { in =>
154
- (in ++ Stream .exec (close.void) )
154
+ in.onFinalize (close.void)
155
155
.evalMap(send)
156
156
.takeWhile(_.isRight)
157
157
.drain
Original file line number Diff line number Diff line change @@ -208,7 +208,7 @@ object Topic {
208
208
}
209
209
210
210
def publish : Pipe [F , A , Nothing ] = { in =>
211
- (in ++ Stream .exec (close.void) )
211
+ in.onFinalize (close.void)
212
212
.evalMap(publish1)
213
213
.takeWhile(_.isRight)
214
214
.drain
Original file line number Diff line number Diff line change @@ -323,4 +323,19 @@ class ChannelSuite extends Fs2Suite {
323
323
racingSendOperations(channel)
324
324
}
325
325
326
+ test(" stream should terminate when sendAll is interrupted" ) {
327
+ val program =
328
+ Channel
329
+ .bounded[IO , Unit ](1 )
330
+ .flatMap { ch =>
331
+ val producer =
332
+ Stream
333
+ .eval(IO .canceled)
334
+ .through(ch.sendAll)
335
+
336
+ ch.stream.concurrently(producer).compile.drain
337
+ }
338
+
339
+ TestControl .executeEmbed(program) // will fail if program is deadlocked
340
+ }
326
341
}
Original file line number Diff line number Diff line change @@ -185,4 +185,25 @@ class TopicSuite extends Fs2Suite {
185
185
186
186
TestControl .executeEmbed(program) // will fail if program is deadlocked
187
187
}
188
+
189
+ test(" publisher cancellation does not deadlock" ) {
190
+ val program =
191
+ Topic [IO , String ]
192
+ .flatMap { topic =>
193
+ val publisher =
194
+ Stream
195
+ .constant(" 1" )
196
+ .covary[IO ]
197
+ .evalTap(_ => IO .canceled)
198
+ .through(topic.publish)
199
+
200
+ Stream
201
+ .resource(topic.subscribeAwait(1 ))
202
+ .flatMap(subscriber => subscriber.concurrently(publisher))
203
+ .compile
204
+ .drain
205
+ }
206
+
207
+ TestControl .executeEmbed(program) // will fail if program is deadlocked
208
+ }
188
209
}
You can’t perform that action at this time.
0 commit comments