Class: Rage::Application
- Inherits:
-
Object
- Object
- Rage::Application
- Defined in:
- lib/rage/application.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(router) ⇒ Application
constructor
A new instance of Application.
Constructor Details
#initialize(router) ⇒ Application
Returns a new instance of Application.
4 5 6 7 8 9 |
# File 'lib/rage/application.rb', line 4 def initialize(router) Iodine.on_state(:on_start) do Fiber.set_scheduler(Rage::FiberScheduler.new) end @router = router end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rage/application.rb', line 11 def call(env) fiber = Fiber.schedule do handler = @router.lookup(env) if handler handler[:handler].call(env, handler[:params]) else [404, {}, ["Not Found"]] end rescue => e [500, {}, ["#{e.class}:#{e.}\n\n#{e.backtrace.join("\n")}"]] ensure # notify Iodine the request can now be served Iodine.publish(env["IODINE_REQUEST_ID"], "") end # the fiber encountered blocking IO and yielded; instruct Iodine to pause the request; if fiber.alive? [:__http_defer__, fiber] else fiber.__get_result end end |