# Channel take if available

**URL:** https://discourse.julialang.org/t/channel-take-if-available/73252
**Category:** General Usage
**Tags:** question, channel
**Created:** [December 17, 2021, 11:59am UTC](https://discourse.julialang.org/t/channel-take-if-available/73252 "2021-12-17T11:59:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)
#### Post date: [December 17, 2021, 11:59am UTC](https://discourse.julialang.org/t/channel-take-if-available/73252/1 "2021-12-17T11:59:55Z")

</div>

Hi all 🙂

Is there a way to take an element from a `Channel` if and only if there are elements available. This should be non blocking.

I could do something like:

```julia
julia> c = Channel(10)
Channel{Any}(10) (empty)

julia> !isempty(c) && take!(c)
false

julia> put!(c, :element)
:element

julia> !isempty(c) && take!(c)
:element

```

But this is not thread safe. Because after `!isempty(c)` is called a different thread could wake up and take from `c`

---

<div class="post-metadata">

### Author: ![findmyway](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/findmyway/32/4946_2.png) [@findmyway](https://discourse.julialang.org/u/findmyway)
#### Post date: [December 17, 2021, 1:55pm UTC](https://discourse.julialang.org/t/channel-take-if-available/73252/2 "2021-12-17T13:55:54Z")

</div>

Looks like we do not have such function yet based on the last paragraph in [add maybetake! and tryput! by tkf · Pull Request #41966 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/41966)

> Note also that this PR does not implement the “non-blocking” version of put/take. However, it is conceivable to add `maybetake_nowait!` and `tryput_nowait!` in the future (with a warning in the docstring that they are “racy” APIs and it is discouraged to use them, unless you know what you are doing.)
