Project

Go.rb

0.0
No commit activity in last 3 years
No release in over 3 years
'Go' is a language that specializes in concurrency and control flow, but some people (myself included) don't like the choice of Syntax. Not only that, but these features are something that could be useful in other projects, hence why I created 'GoRuby', bringing the Concurrency and Control Flow features of 'Go' into Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Go.rb

A lightweight Ruby concurrency system with multi-thread and multi-process support with Pipes and Channels. Build Status Gem Version Coverage Status Code Climate

Why?

Go.rb is inspired by the 'Go' programming language. 'Go' excels in concurrency, so I decided to recreate some of these features in Ruby. This includes easy creation and management of Threads and Process-Forking. Channels allow communication across Threads and Pipes allow for data interchange across Processes.

Getting Started

Getting started with Go.rb is very simple. First, install the Gem:

  gem install Go.rb

or, in your gem file:

  gem 'Go.rb'

Using the gem is very simple. Here are a few examples:

require 'go'

go { puts "Hello World" }
go { puts "Goodbye World" }

# => "Hello World"
# => "Goodbye World"

In the above case, both "Hello World" and "Goodbye World" are executed in their own, individual threads.

require 'go'

go do
  sleep 1
  puts "Hello World"
end
go { puts "Goodbye World" }

# => "Goodbye World"
# => "Hello World"

Additionally, Multiple Processes are supported.

require 'go'

gofork { puts "Hello from another Process" }
gofork { sleep 1 }.wait

# => "Hello from another Process"
# => *waits 1 second before exiting*

For communication across Threads, a Channels system is implemented. Channels can hold any object

require 'go'

channel = gochan    # Create a new Channel
go(channel) { |chan| chan << "Hello World" }
puts channel.get

# => "Hello World"

channel << "Hi Earth"
channel2 = gochan
go(channel, channel2) { |chan, chan2| chan2 << chan.get }
puts channel2.get

# => "Hi Earth"

For communication across Processes, a Pipes system is implemented. Objects can not be transferred across processes, only byte streams like binary strings.

require 'go'

pipe = gopipe
gofork(pipe) { |pipe| pipe << "Hello" }
puts pipe.read(5)

# => "Hello"

pipe.puts "Hello World"
gofork(pipe) { |pipe| puts pipe.gets }

# => "Hello World"
pipe.close