Repository navigation
Modern Chan Channel Channel
Paul Squires edited this page Oct 19, 2026
·
5 revisions
Home › Goroutines and Channels › Goroutines and Channels › Channel
Holds a typed queue between goroutines; copies share it, and a new one is nil.
Channel( of T )( [ capacity ] )- A capacity of 0 is a RENDEZVOUS, not a zero-length buffer.
Sendblocks until a receiver takes the value, and the value is handed over directly rather than through the buffer -- which makes the rendezvous an ordering point as well as a handoff. -
Copies SHARE. A Channel is a refcounted handle to a channel, not a channel. Handing a copy to each of four workers gives four handles on one queue, which is what makes fan-out work. Deliberately unlike
containers.Array, whose copy is deep. - A default-constructed channel is NIL, and a nil channel blocks forever on
SendandReceive. That is Go's rule, andIsNilexists so a program can assert its own initialisation -- "my program hangs" is the symptom of forgetting it. - The destructor does not Close. Closing means "no more values will be sent", and a scope that merely stopped holding a reference has not said that.
- Requires
-mt; the header refuses to compile without it.
#import "std/tasks"
using tasks
dim ch as Channel( of int32 ) = Channel( of int32 )( 4 )
print ch.Capacity( ) '' 4
print ch.IsNil( ) '' false -- constructed, not default
dim as int32 v = 42
ch.TrySend( v )
print ch.Count( ) '' 1
dim as int32 got
ch.TryReceive( got )
print got '' 42
'' A DEFAULT-CONSTRUCTED channel is nil, and blocks forever if used
dim nilch as Channel( of int32 )
print nilch.IsNil( ) '' trueLibrary: Goroutines and Channels
Category: Goroutines and Channels
Documented under: Members
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing