Concurrent::ProcessingActor < Synchronization::Object
| Use Case | Command | Description |
|---|---|---|
| Create an actor with initial value | Concurrent::ProcessingActor.act(initial) { |actor, val| ... } | Creates a new processing actor on a shared thread pool |
| Send a message | actor.tell(message) | Sends an asynchronous message to the actor |
| Receive a message | actor.receive { |msg| ... } | Receives a message from the actor's mailbox |
| Get termination value | actor.termination.value | Retrieves the final value after the actor completes |
A new implementation of actor which also simulates the process, therefore it can be used in the same way as Erlang's actors but without occupying thread. A tens of thousands ProcessingActors can run at the same time sharing a thread pool.
# Runs on a pool, does not consume 50_000 threads
actors = 50_000.times.map do |i|
Concurrent::ProcessingActor.act(i) { |a, i| a.receive.then_on(:fast, i) { |m, i| m + i } }
end
actors.each { |a| a.tell 1 }
values = actors.map(&:termination).map(&:value)
values[0,5] # => [1, 2, 3, 4, 5]
values[-5, 5] # => [49996, 49997, 49998, 49999, 50000]
⚠️ @!macro warn.edge
actact_listeningnewask_opinspectmailboxreceivetell!tell_opterminationto_aryto_sGenerated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-27 16:33 @216.73.216.194
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format