Start a slow API call or database query in the background using a Promise and retrieve the result later without blocking the rest of your program.
Schedule recurring background jobs at fixed intervals using TimerTask without adding an external job queue or worker process.
Replace Ruby's standard Hash or Array with thread-safe versions to prevent data corruption in multi-threaded Rails or Sinatra apps.
Add async behavior to any Ruby class with the Async mixin so it handles concurrent work without requiring a full actor framework.
Concurrent Ruby is a library that gives Ruby developers a collection of tools for writing programs that do multiple things at the same time without running into conflicts. When several parts of a program try to read or change the same data at once, hard-to-reproduce bugs can appear. This library provides structures and patterns designed to prevent those kinds of problems, and it works consistently across the three main Ruby versions: MRI/CRuby, JRuby, and TruffleRuby. The library draws ideas from several other programming languages and communities. Erlang contributed the notion of isolated processes passing messages rather than sharing memory. Clojure, Scala, Haskell, and Java contributed patterns for futures, promises, and immutable data. The result is a Ruby gem that brings the safest and most practical of those ideas into the Ruby language without introducing any external gem dependencies. At the core are general-purpose building blocks for managing work that happens in the background. Promises let you start a computation and retrieve its result later without blocking the rest of your program. ScheduledTask runs a piece of work at a specific point in the future. TimerTask wakes up at regular intervals to perform background work. The Async mixin adds straightforward asynchronous behavior to any class with minimal setup. The library also provides thread-safe versions of Ruby's common data containers: arrays, hashes, sets, and a Map type designed to perform well under high concurrency. There are immutable value types too, such as ImmutableStruct, for situations where you want to guarantee that an object cannot be changed after it is created. The design philosophy is to offer a broad set of options without pushing a particular style. The library avoids debates about which concurrency pattern is superior, keeps its own codebase small, and aims to keep the API feeling like natural Ruby rather than a translation from another language.
← ruby-concurrency on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.