This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module RactorPool | |
| # using the ForkedJoin pattern - https://en.wikipedia.org/wiki/Fork%E2%80%93join_model | |
| # this creates a worker pool (of Ractors) as large as the number of input messages | |
| # and then collects the results upon completion - at which point the Ractors are | |
| # removed from the worker pool and available to be garbage collected | |
| # note: the injected behavior must respond to #call(input) | |
| # usage: define a behavior that responds to #call(input) | |
| # class Fibonacci | |
| # def call(n) = [n, fib(n)] | |
| # def fib(n) = n < 2 ? 1 : fib(n-2) + fib(n-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module RactorPool | |
| # static sized pool with supervision | |
| # use multi_use at own risk - be sure to collect results before submitting more messages | |
| class WorkerPool | |
| attr_reader :behavior, :inputs, :input_queue, :multi_use, :worker_count, :workers_pool | |
| def self.call(input, behavior, options = {}) | |
| new(input, behavior, options) | |
| end |
OlderNewer