<commit_before>---
layout: post
title:  "Golang Channels"
date:   2016-12-17 18:00:00 -0800
categories: programming-languages
---

The Go Programming Language has built-in communication channels, which provide type-safe one-way or two-way communication between processes.  This can be very useful for concurrent programming, such as in master-slave and map-reduce programs.

Channels can be buffered or unbuffered, where buffered channels can store multiple messages up to a declared capacity.  Once a channel is full, it blocks further writes until a process initiates a read operation.

```go
// An unbuffered integer channel, which blocks writes
// until another process is waiting to receive messages
unbufferedIntChannel := make(chan int)

// A buffered string channel, which can carry up to 4
// messages before blocking writes
bufferedStrChannel := make(chan string, 4)

// Write to a channel
bufferedStrChannel <- "Hello world!"
bufferedStrChannel <- "Your move."

// Read from a channel
message1 := <-bufferedStrChannel // "Hello world!"
message2 := <-bufferedStrChannel // "Your move."
<commit_msg>Standardize capitalization of post title<commit_after>---
layout: post
title:  "Golang channels"
date:   2016-12-17 18:00:00 -0800
categories: programming-languages
---

The Go Programming Language has built-in communication channels, which provide type-safe one-way or two-way communication between processes.  This can be very useful for concurrent programming, such as in master-slave and map-reduce programs.

Channels can be buffered or unbuffered, where buffered channels can store multiple messages up to a declared capacity.  Once a channel is full, it blocks further writes until a process initiates a read operation.

```go
// An unbuffered integer channel, which blocks writes
// until another process is waiting to receive messages
unbufferedIntChannel := make(chan int)

// A buffered string channel, which can carry up to 4
// messages before blocking writes
bufferedStrChannel := make(chan string, 4)

// Write to a channel
bufferedStrChannel <- "Hello world!"
bufferedStrChannel <- "Your move."

// Read from a channel
message1 := <-bufferedStrChannel // "Hello world!"
message2 := <-bufferedStrChannel // "Your move."

{'fraction_non_alphanumeric': 0.07935800267498885, 'fraction_numerical': 0.01961658493089612, 'mean_word_length': 4.4072289156626505, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7237587', 'n_tokens_mistral': 612, 'n_tokens_neox': 549, 'n_words': 278}