From 85374248a0684bbec337eff41d741d5deb963f14 Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Sun, 4 Aug 2024 01:02:34 +0200 Subject: [PATCH] Implement Base.isempty(::RemoteChannel) The default method from Base has the nasty side-effect of take!()'ing from the underlying channel. --- src/remotecall.jl | 3 +++ test/distributed_exec.jl | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/remotecall.jl b/src/remotecall.jl index 0b1143d..644ff04 100644 --- a/src/remotecall.jl +++ b/src/remotecall.jl @@ -768,6 +768,9 @@ close(rr::RemoteChannel) = call_on_owner(close_ref, rr) isopen_ref(rid) = isopen(lookup_ref(rid).c) isopen(rr::RemoteChannel) = call_on_owner(isopen_ref, rr) +isempty_ref(rid) = isempty(lookup_ref(rid).c) +Base.isempty(rr::RemoteChannel) = call_on_owner(isempty_ref, rr) + getindex(r::RemoteChannel) = fetch(r) getindex(r::Future) = fetch(r) diff --git a/test/distributed_exec.jl b/test/distributed_exec.jl index 71b6b36..71f6ac6 100644 --- a/test/distributed_exec.jl +++ b/test/distributed_exec.jl @@ -497,6 +497,18 @@ let ch = RemoteChannel(() -> Channel(1)) @test 10 == test_iteration_collect(ch) end +# Test isempty(::RemoteChannel). This should not modify the underlying +# AbstractChannel, which Base's default implementation will do. +let + chan = Channel(1) + push!(chan, 1) + remotechan = RemoteChannel(() -> chan) + + @test !isempty(remotechan) + # Calling `isempty(remotechan)` shouldn't have modified `chan` + @test !isempty(chan) +end + # make sure exceptions propagate when waiting on Tasks @test_throws CompositeException (@sync (@async error("oops"))) try