I feel like the linked article is based heavily on my own article on the same subject: https://brunosutic.com/blog/ruby-fiber-scheduler
Too bad the article doesn't contain the source reference, but oh well. I hope it gets the word out about this new cool stuff in Ruby.
ReplyCan this be used for UI callbacks as well, like async/await in C# and coroutines in Kotlin?
In other words, with an appropriate fiber scheduler, could I start a function on the UI thread, suspend it while performing some background operation and then resume the same function again on the UI thread?
Replyi think this announcement https://brunosutic.com/blog/async-ruby & the associated async libraries (https://github.com/socketry/async) do a much better job of showing off the potential for the ruby 3.1+ fiber scheduler. Async gem is powered by a fiber scheduler under the hood, and what you get is un-colored async-ready ruby code.
That is to say, you can write a normal rack app with falcon-async as the webserver and get node/event-loop scale co-operative concurrency without changing your code. Its pretty exciting!
Unfortunately rails makes heavy use of thread locals which arent compatible with fiber concurrency, so its going to take awhile until its async-ready, but I believe progress is being made (Async ActiveRecord was merged recently).
Replysite design / logo © 2022 Box Piper