Giter VIP home page Giter VIP logo

concurrent-ruby's Introduction

Concurrent Ruby Build Status Coverage Status Dependency Status

Modern concurrency tools for Ruby. Inspired by Erlang, Clojure, Scala, Haskell, F#, C#, Java, and classic concurrency patterns.

The design goals of this gem are:

  • Stay true to the spirit of the languages providing inspiration
  • But implement in a way that makes sense for Ruby
  • Keep the semantics as idiomatic Ruby as possible
  • Support features that make sense in Ruby
  • Exclude features that don't make sense in Ruby
  • Be small, lean, and loosely coupled

Features & Documentation

Semantic Versioning

This gem adheres to the rules of semantic versioning.

Supported Ruby versions

MRI 1.9.2, 1.9.3, 2.0, 2.1, JRuby (1.9 mode), and Rubinius 2.x. This library is pure Ruby and has no gem dependencies. It should be fully compatible with any Ruby interpreter that is 1.9.x compliant.

Example

Many more code examples can be found in the documentation for each class (linked above). This one simple example shows some of the power of this gem.

require 'concurrent'
require 'faker'

class EchoActor < Concurrent::Actor
  def act(*message)
    puts "#{message} handled by #{self}"
  end
end

mailbox, pool = EchoActor.pool(5)

timer_proc = proc do
  mailbox.post(Faker::Company.bs)
end

t1 = Concurrent::TimerTask.new(execution_interval: rand(5)+1, &timer_proc)
t2 = Concurrent::TimerTask.new(execution_interval: rand(5)+1, &timer_proc)

overlord = Concurrent::Supervisor.new

overlord.add_worker(t1)
overlord.add_worker(t2)
pool.each{|actor| overlord.add_worker(actor)}

overlord.run!

#=> ["mesh proactive platforms"] handled by #<EchoActor:0x007fa5ac18bdf8>
#=> ["maximize sticky portals"] handled by #<EchoActor:0x007fa5ac18bdd0>
#=> ["morph bleeding-edge markets"] handled by #<EchoActor:0x007fa5ac18bd80>
#=> ["engage clicks-and-mortar interfaces"] handled by #<EchoActor:0x007fa5ac18bd58>
#=> ["monetize transparent infrastructures"] handled by #<EchoActor:0x007fa5ac18bd30>
#=> ["morph sexy e-tailers"] handled by #<EchoActor:0x007fa5ac18bdf8>
#=> ["exploit dot-com models"] handled by #<EchoActor:0x007fa5ac18bdd0>
#=> ["incentivize virtual deliverables"] handled by #<EchoActor:0x007fa5ac18bd80>
#=> ["enhance B2B models"] handled by #<EchoActor:0x007fa5ac18bd58>
#=> ["envisioneer real-time architectures"] handled by #<EchoActor:0x007fa5ac18bd30>

overlord.stop

Disclaimer

Remember, there is no silver bullet in concurrent programming. Concurrency is hard. These tools will help ease the burden, but at the end of the day it is essential that you know what you are doing.

  • Decouple business logic from concurrency logic
  • Test business logic separate from concurrency logic
  • Keep the intersection of business logic and concurrency and small as possible
  • Don't share mutable data unless absolutely necessary
  • Protect shared data as much as possible (prefer immutability)
  • Don't mix Ruby's concurrency primitives with asynchronous concurrency libraries

Contributors

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Conference Presentations

I've given several conference presentations on concurrent programming with this gem. Check them out:

License and Copyright

Concurrent Ruby is Copyright © 2013 Jerry D'Antonio. It is free software released under the MIT License.

concurrent-ruby's People

Contributors

jdantonio avatar mighe avatar brixen avatar gcapizzi avatar jamiehodge avatar zph avatar

Watchers

Krzysztof Ściubisz avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.