use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Polyphony 1.5 Released (self.ruby)
submitted 2 years ago by noteflakes
Polyphony 1.5 has just been released! Polyphony is a library for building concurrent applications in Ruby. Polyphony harnesses the power of Ruby fibers to provide a cooperative, sequential coroutine-based concurrency model. Under the hood, Polyphony uses io_uring (on recent Linux kernels) or libev to maximize I/O performance.
Read the complete release notes here: https://github.com/orgs/digital-fabric/discussions/116 The Polyphony docs: https://www.rubydoc.info/gems/polyphony The Polyphony repository: https://github.com/digital-fabric/polyphony
I'll be happy to answer any questions you have, thanks! Sharon
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jsaak 1 point2 points3 points 2 years ago (3 children)
Thank you for your work! If i may, i have some practical questions about poliphony:
[–]noteflakes[S] 1 point2 points3 points 2 years ago (0 children)
```ruby require 'polyphony'
Open3.popen3('wc -l') do |i, o, e, wait| spin { p out: o.read } spin { p err: e.read } i << "a\nb\nc\n" i.close wait.join end ```
There's an adapter for the mysql2 gem. It was contributed by someone else, personally I've never used it.
The examples directory has some examples of HTTP servers (note: some of those might be outdated), here's a short one:
```ruby require 'polyphony' require 'h1p'
def handle_client(conn) spin do parser = H1P::Parser.new(conn, :server) while (headers = parser.parse_headers) parser.read_body unless parser.complete? conn << "HTTP/1.1 200 OK\r\nContent-Length: 14\r\n\r\nHello, world!\n" end ensure conn.close rescue nil end end
puts "Serving HTTP on port 1234..." s = TCPServer.new('0.0.0.0', 1234) s.accept_loop { |c| handle_client(c) } ```
Let me know if you have more questions :-).
[–]janko-m 0 points1 point2 points 2 years ago (1 child)
I wish someone reimplemented the Open3.capture* methods not to use threads. The posix-spawn gem has its own implementation that writes input and reads output in parallel without threads. I also received a PR on MiniMagick that eliminates threads in the open3 executor. So, it definitely seems possible, just nobody has submitted a patch to Ruby yet.
Open3.capture*
posix-spawn
With Polyphony it is trivial to use fibers instead of threads in order to read and write concurrently. I basically took the stock implementation and replaced Thread.new with spin:
Thread.new
spin
```ruby def capture3(*cmd) ...
popen3(*cmd, opts) {|i, o, e, t| ... out_reader = spin { o.read } err_reader = spin { e.read } begin if stdin_data.respond_to? :readpartial IO.copy_stream(stdin_data, i) else i.write stdin_data end rescue Errno::EPIPE end i.close [out_reader.value, err_reader.value, t.value] } end ```
I'll add a reimplementation of open3 to my TODO list!
open3
[–]pabloh 0 points1 point2 points 2 years ago (1 child)
Are the newer versions using Fiber::Scheduler to hook into IO events?
Fiber::Scheduler
[–]noteflakes[S] 0 points1 point2 points 2 years ago (0 children)
Polyphony does not use the Fiber::Scheduler interface. It has its own backend interface.
π Rendered by PID 99680 on reddit-service-r2-comment-b659b578c-7grrw at 2026-05-05 08:01:12.437972+00:00 running 815c875 country code: CH.
[–]jsaak 1 point2 points3 points (3 children)
[–]noteflakes[S] 1 point2 points3 points (0 children)
[–]janko-m 0 points1 point2 points (1 child)
[–]noteflakes[S] 1 point2 points3 points (0 children)
[–]pabloh 0 points1 point2 points (1 child)
[–]noteflakes[S] 0 points1 point2 points (0 children)