Constructs a Channel that can hold a maximum of sz objects of type T. put! calls on a full channel block till an object is removed with take!.

Other constructors:

  • Channel() - equivalent to Channel{Any}(32)
  • Channel(sz::Int) equivalent to Channel{Any}(sz)


  1. Create a channel of integers with a specified size:

    julia> ch = Channel{Int}(5)

    This example creates a channel ch that can hold a maximum of 5 integers.

  2. Create a channel of strings:

    julia> str_ch = Channel{String}()

    Here, we create a channel str_ch that can hold a maximum of 32 strings.

  3. Put an object into the channel:

    julia> put!(ch, 10)

    This code puts the value 10 into the channel ch.

  4. Take an object from the channel:

    julia> value = take!(ch)

    It retrieves an object from the channel ch and assigns it to the variable value.

  5. Use Channel() as a default constructor:

    julia> default_ch = Channel()

    This creates a channel default_ch with a default type Any and a maximum size of 32.

  6. Create a channel with a specific size using Channel(sz::Int):
    julia> custom_ch = Channel(10)

    This code creates a channel custom_ch with a maximum size of 10.

Note: The put! and take! functions are used for adding and retrieving objects from the channel, respectively. It's important to note that put! calls on a full channel will block until space becomes available by removing objects using take!.

See Also

Channel, close, put!, take!,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: