Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default FiberScheduler to rage console #125

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

TheBlackArroVV
Copy link
Contributor

Closes #115

Copy link
Member

@rsamoilov rsamoilov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @TheBlackArroVV , thank you for the PR! This is pretty much what we are looking for, but it doesn't work correctly in all cases.

It works fine with synchronous fibers (e.g. Fiber.schedule { rand }) but doesn't work correctly with asynchronous.

For example, running the following code in the console raises attempt to yield on a not resumed fiber (FiberError):

require "net/http"
Fiber.await(Fiber.schedule { Net::HTTP.get(URI("http://httpbin.org/delay/1")) })

The reason for that is that Rage::FiberScheduler is using the server's reactor - if the server is not running, the scheduler will not work. Thus, we will likely need a mock scheduler here, similar to the one we use in tests.

@TheBlackArroVV
Copy link
Contributor Author

Hey, @rsamoilov,
I have updated it, should be good now. I tried to make it work with refinements, but, unfortunately looks like new console is outside of it's scope

lib/rage/cli.rb Outdated Show resolved Hide resolved
spec/rage/sync_fiber_spec.rb Outdated Show resolved Hide resolved
Array(fibers).map(&:__get_result)
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this is the same as requiring the file 😞
This patch also applies to the server process, effectively making all code inside the application synchronous.

You can verify this by creating a new Rage app and adding an action that calls sleep 1. Sending however many requests in parallel to this action should only take one second, but with these changes Rage will be processing the requests one by one.

Instead, we only want these changes applied to the console method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐞 Using Fiber.schedule in console
2 participants