# RemoteChannel allows more inputs than I defined

**URL:** <https://discourse.julialang.org/t/remotechannel-allows-more-inputs-than-i-defined/45814>\
**Category:** New to Julia\
**Created:** [August 31, 2020, 4:47am UTC](https://discourse.julialang.org/t/remotechannel-allows-more-inputs-than-i-defined/45814 "2020-08-31T04:47:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noel\_Araujo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noel_araujo/32/4862_2.png) [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Post date:** [August 31, 2020, 4:47am UTC](https://discourse.julialang.org/t/remotechannel-allows-more-inputs-than-i-defined/45814/1 "2020-08-31T04:47:36Z")

</div>

Hellos

I am creating a pipeline with `RemoteChannel` (if it does not work, I’ll create other post asking for help again), and I noticed that I can add more data than I specified.  
I don’t know if I am just confused with the syntax and misunderstood how to defined the size of the channel, or it is actually a bug. Here the code:

```julia
# begin with a simple channel to test that my pc is working 
c1 = Channel(5)

put!(c1, 1)
put!(c1, 2)
put!(c1, 3)
put!(c1, 4)
put!(c1, 5)
# the next line does not work as expected
put!(c1, 6)
# if I did not run the previous line, the next line works
values = [take!(c1) for i=1:5]

using Distributed
addprocs(4)
const r_c1 = RemoteChannel(()->Channel{Int}(5));
# const r_c1 = RemoteChannel(()->Channel(1), 5); ## ? maybe this way

@spawnat 2 begin put!(r_c1, 1) end;
@spawnat 3 begin put!(r_c1, 2) end;
@spawnat 2 begin put!(r_c1, 3) end;
@spawnat 3 begin put!(r_c1, 4) end;
@spawnat 2 begin put!(r_c1, 5) end;
# somehow I can put values in the Channel
@spawnat 3 begin put!(r_c1, 6) end;
# if I DO run the previous line, the following line also works
values = [take!(r_c1) for i=1:6]

```

I am open to any explanation

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [August 31, 2020, 6:12am UTC](https://discourse.julialang.org/t/remotechannel-allows-more-inputs-than-i-defined/45814/2 "2020-08-31T06:12:54Z")

</div>

In the first part of your example `put!(c1, 6)` blocks the user process since everything is done sequentially.

In the 2nd part with

`@spawnat 3 begin put!(r_c1, 6) end;`

you start a closure asynchronously on process 3, which blocks immediately (but in the background) since the channel is full until you begin `take!`ing the values out in the next line.

The difference is only _sequentially_ vs _asynchronously_.

---

<div class="post-metadata">

**Author:** ![Noel\_Araujo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noel_araujo/32/4862_2.png) [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Post date:** [August 31, 2020, 6:52am UTC](https://discourse.julialang.org/t/remotechannel-allows-more-inputs-than-i-defined/45814/3 "2020-08-31T06:52:46Z")

</div>

🤔Just to be sure that I understood:

- When I run `@spawnat 3 begin put!(r_c1, 6) end;`, the julia process 3 indeed is blocked and waiting for `r_c1` to be free.
- Because I made a `@spawat`, I do not see this happening.
- The line `values = [take!(r_c1) for i=1:6]` works because when I made the first `take!`, automatically the `r_c1` had a free space, and julia process 3 put its new value

am I right ?

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [August 31, 2020, 7:04am UTC](https://discourse.julialang.org/t/remotechannel-allows-more-inputs-than-i-defined/45814/4 "2020-08-31T07:04:54Z")

</div>

> [@Noel\_Araujo](#):
>
> Because I made a `@spawnat` , I do not see this happening.

yes!

Consider the following MWE:

The following blocks (freezes) the user process at step 6 of the for loop:

```julia
ch = Channel(5)
for i in 1:6
    put!(ch, i)
end
values = [take!(ch) for _ in 1:6]

```

the following does not block the user process but the `@async` task:

```julia
ch = Channel(5)
@async for i in 1:6
    put!(ch, i)
end
values = [take!(ch) for _ in 1:6]

```

When you start to `take!` out the values, the task continues and delivers the 6th value asynchronously.
