Go-lightly is a Clojure library that facilitates building concurrent programs in Clojure in the style built into the Go language. Go concurrency is based on the Communicating Sequential Processes (CSP) model of programming.
CSP addresses concurrency interaction patterns - how separate processes, threads or routines communicate and coordinate with each other via message passing. A CSP language or library is intended to provided constructs that reduce the complexity of inter-process/inter-thread communication using primitives that are easy to use and reason about. This means not having to be a deep expert in a system's memory model in order to do concurrent programming. Instead, it hides semaphores, mutexes, barriers and other low level concurrency constructs in higher-level abstractions.
This repo is split into two parts:
To run the Go examples you will need Go installed. See the README in go-lightly-examples/go-examples/
.
The clojure examples are in a lein project. See the README in go-lightly-examples/clj-examples/
.
The core constructs of Go's concurrent programming model are:
select
operator that reads the next available message from multiple channelsThe go-lightly library provides all of these (plus a few extras) by wrapping features already provided in the JVM and Clojure. It is composed of one file: the thornydev.go-lightly namespace that defines helper macros and functions. There is a test for it in the usual spot (using lein project structure).
I have provided a number of usage examples that I assembled or wrote while thinking about how to develop this library.
There are basically 4 categories of examples:
Each example can be loaded up and run in the REPL.
Because I want to make sure all of these will run and end gracefully (not hang), I also set up a massive case statement in the thornydev.go-lightly.run-examples/-main
method to most of these via lein run
. Most can run be run with other targets, but some cannot since they take additional arguments. See the run-examples.clj file for details.
Example:
$ lein run :gen-amp :gen-lam1 :goog3.0
will run all three of those targets sequentially.
For details on the most important examples see the README in the clj-examples directory.
Copyright © 2012 Michael Peterson
Some of the example code in the go-examples directory is copyright Rob Pike or and some in go-examples and clj-examples is copyright Alexey Kachayev.
Distributed under the Eclipse Public License, the same as Clojure.
Can you improve this documentation? These fine people already did:
Michael & Michael PetersonEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close