Class: Spring::ApplicationManager

Inherits:
Object
  • Object
show all
Includes:
Mutex_m
Defined in:
lib/spring/application_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ ApplicationManager

Returns a new instance of ApplicationManager.



11
12
13
14
# File 'lib/spring/application_manager.rb', line 11

def initialize(env)
  super()
  @env = env
end

Instance Attribute Details

#childObject (readonly)

Returns the value of attribute child.



9
10
11
# File 'lib/spring/application_manager.rb', line 9

def child
  @child
end

#envObject (readonly)

Returns the value of attribute env.



9
10
11
# File 'lib/spring/application_manager.rb', line 9

def env
  @env
end

#pidObject (readonly)

Returns the value of attribute pid.



9
10
11
# File 'lib/spring/application_manager.rb', line 9

def pid
  @pid
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/spring/application_manager.rb', line 28

def alive?
  @pid
end

#restartObject



21
22
23
24
25
26
# File 'lib/spring/application_manager.rb', line 21

def restart
  # Restarting is a background operation. If it fails, we don't want
  # any terminal output. The user will see the output when they next
  # try to run a command.
  start_child(true)
end

#run(client) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/spring/application_manager.rb', line 32

def run(client)
  @client = client

  synchronize do
    start unless alive?

    begin
      child.send_io @client
    rescue Errno::EPIPE
      # EPIPE indicates child has died but has not been collected by the wait thread yet
      start
      child.send_io @client
    end
  end
ensure
  @client.close
  @client = nil
end

#startObject



16
17
18
19
# File 'lib/spring/application_manager.rb', line 16

def start
  start_child
  start_wait_thread
end