Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobnissen committed May 25, 2024
1 parent d358d94 commit 3d6a2bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,11 @@ function iterate(c::Channel, state=nothing)
end
end
else
check_channel_state(c)
# If the channel was closed with an exception, it needs to be thrown
if (@atomic :acquire c.state) === :closed
excp = c.excp
excp !== nothing && throw(excp)
end
return nothing
end
end
Expand Down
6 changes: 4 additions & 2 deletions test/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,17 +506,19 @@ struct CustomError <: Exception end
@test_throws InvalidStateException Base.check_channel_state(c)

# Issue 52974 - closed channels with exceptions
# must be thrown on iteration
# must be thrown on iteration, if channel is empty
c = Channel(2)
put!(c, 5)
close(c, CustomError())
@test take!(c) == 5
@test_throws CustomError iterate(c)

c = Channel(Inf)
put!(c, 1)
close(c)
@test take!(c) == 1
@test_throws InvalidStateException take!(c)
@test_throws InvalidStateException put!(c)
@test_throws InvalidStateException put!(c, 5)
end

# PR #36641
Expand Down

0 comments on commit 3d6a2bd

Please sign in to comment.