Concurrency is a form of computing in which several computations are executed during overlapping time periods—concurrently—instead of sequentially (one completing before the next starts). This is a property of a system—this may be an individual program, a computer, or a network—and there is a separate execution point or "thread of control" for each computation ("process"). A concurrent system is one where a computation can advance without waiting for all other computations to complete.
Modern concurrency tools include agents, futures, promises, thread pools actors, supervisors etc.Concurrent Ruby makes the strongest thread safety guarantees of any Ruby concurrency library. Every abstraction in this library is thread safe. Similarly, all are deadlock free and many are fully lock free.
Concurrent Ruby is a set of 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:
- Be an 'unopinionated' toolbox that provides useful utilities without debating which is better or why
- Remain free of external gem dependencies
- 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
- Async (Concurrent::Async): A mixin module that provides simple asynchronous behavior to a class, turning it into a simple actor.
- Future (Concurrent::Future): An asynchronous operation that produces a value. It represents a promise to complete an action at some time in the future.
- Dataflow: Built on Futures, Dataflow allows you to create a task that will be scheduled when all of its data dependencies are available.
- Promise (Concurrent::Promise): Similar to Futures, with more features. It represents the eventual value returned from the single completion of an operation.
- ScheduledTask (Concurrent::ScheduledTask): Like a Future scheduled for a specific future time.
- TimerTask (Concurrent::TimerTask): A Thread that periodically wakes up to perform work at regular intervals.
gem install concurrent-ruby
or add the following line to Gemfile:
gem 'concurrent-ruby', require: 'concurrent'
bundle install from your shell
Everything within this gem can be loaded simply by requiring it:
To use the tools in the Edge gem it must be required separately:
See GitHub for more info.