Created
August 11, 2011 17:31
-
-
Save abstractj/1140245 to your computer and use it in GitHub Desktop.
service_injection_demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyController < ApplicationController | |
include TorqueBox::Injectors | |
def index | |
service = inject('service:MyService') | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyService | |
def initialize(opts={}) | |
@name = opts['name'] | |
end | |
def start | |
Thread.new { run } | |
end | |
def stop | |
@done = true | |
end | |
def run | |
until @done | |
puts "Hello #{@name}" | |
sleep(1) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment