Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 28 lines (18 sloc) 0.823 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
package go_koans

func aboutChannels() {
  ch := make(chan string, 2)

  assert(len(ch) == __int__) // channels are like buffers

  ch <- "foo" // i mean, "metaphors are like similes"

  assert(len(ch) == __int__) // they can be queried for queued items

  assert(<-ch == __string__) // items can be popped out of them

  assert(len(ch) == __int__) // and len() always reflects the "current" queue status

  // the 'go' keyword runs a function-call in a new "goroutine"
  // which executes "concurrently" with the calling "goroutine"
  go func() {
    // your code goes here
  }()

  assert(__delete_me__) // we'll need to make room for the queue, or suffer deadlocks

  ch <- "bar" // this send will succeed
  ch <- "quux" // there's enough room for this send too
  ch <- "extra" // but the buffer only has two slots
}
Something went wrong with that request. Please try again.