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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/rage/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
require "rack"
require "rage/version"

# mock fiber methods as RSpec tests don't run concurrently
class Fiber
def self.schedule(&block)
fiber = Fiber.new(blocking: true) do
Fiber.current.__set_id
Fiber.current.__set_result(block.call)
end
fiber.resume

fiber
end

def self.await(fibers)
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.

module Rage
class CLICodeGenerator < Thor
include Thor::Actions
Expand Down
Loading