Class: IRB::JobManager
Overview
job management class
Instance Attribute Summary collapse
-
#current_job ⇒ Object
Returns the value of attribute current_job.
Instance Method Summary collapse
- #delete(key) ⇒ Object
-
#initialize ⇒ JobManager
constructor
A new instance of JobManager.
- #insert(irb) ⇒ Object
- #inspect ⇒ Object
- #irb(key) ⇒ Object
- #kill(*keys) ⇒ Object
- #main_irb ⇒ Object
- #main_thread ⇒ Object
- #n_jobs ⇒ Object
- #search(key) ⇒ Object
- #switch(key) ⇒ Object
- #thread(key) ⇒ Object
Constructor Details
#initialize ⇒ JobManager
Returns a new instance of JobManager.
20 21 22 23 24 |
# File 'lib/irb/ext/multi-irb.rb', line 20 def initialize # @jobs = [[thread, irb],...] @jobs = [] @current_job = nil end |
Instance Attribute Details
#current_job ⇒ Object
Returns the value of attribute current_job
26 27 28 |
# File 'lib/irb/ext/multi-irb.rb', line 26 def current_job @current_job end |
Instance Method Details
#delete(key) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/irb/ext/multi-irb.rb', line 87 def delete(key) case key when Integer IRB.fail NoSuchJob, key unless @jobs[key] @jobs[key] = nil else catch(:EXISTS) do @jobs.each_index do |i| if @jobs[i] and (@jobs[i][0] == key || @jobs[i][1] == key || @jobs[i][1].context.main.equal?(key)) @jobs[i] = nil throw :EXISTS end end IRB.fail NoSuchJob, key end end until assoc = @jobs.pop; end unless @jobs.empty? @jobs.push assoc end |
#insert(irb) ⇒ Object
50 51 52 |
# File 'lib/irb/ext/multi-irb.rb', line 50 def insert(irb) @jobs.push [Thread.current, irb] end |
#inspect ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/irb/ext/multi-irb.rb', line 110 def inspect ary = [] @jobs.each_index do |i| th, irb = @jobs[i] next if th.nil? if th.alive? if th.stop? t_status = "stop" else t_status = "running" end else t_status = "exited" end ary.push format("#%d->%s on %s (%s: %s)", i, irb.context.irb_name, irb.context.main, th, t_status) end ary.join("\n") end |
#irb(key) ⇒ Object
37 38 39 40 |
# File 'lib/irb/ext/multi-irb.rb', line 37 def irb(key) th, irb = search(key) irb end |
#kill(*keys) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/irb/ext/multi-irb.rb', line 64 def kill(*keys) for key in keys th, irb = search(key) IRB.fail IrbAlreadyDead unless th.alive? th.exit end end |
#main_irb ⇒ Object
46 47 48 |
# File 'lib/irb/ext/multi-irb.rb', line 46 def main_irb @jobs[0][1] end |
#main_thread ⇒ Object
42 43 44 |
# File 'lib/irb/ext/multi-irb.rb', line 42 def main_thread @jobs[0][0] end |
#n_jobs ⇒ Object
28 29 30 |
# File 'lib/irb/ext/multi-irb.rb', line 28 def n_jobs @jobs.size end |
#search(key) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/irb/ext/multi-irb.rb', line 72 def search(key) job = case key when Integer @jobs[key] when Irb @jobs.find{|k, v| v.equal?(key)} when Thread @jobs.assoc(key) else @jobs.find{|k, v| v.context.main.equal?(key)} end IRB.fail NoSuchJob, key if job.nil? job end |
#switch(key) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/irb/ext/multi-irb.rb', line 54 def switch(key) th, irb = search(key) IRB.fail IrbAlreadyDead unless th.alive? IRB.fail IrbSwitchedToCurrentThread if th == Thread.current @current_job = irb th.run Thread.stop @current_job = irb(Thread.current) end |
#thread(key) ⇒ Object
32 33 34 35 |
# File 'lib/irb/ext/multi-irb.rb', line 32 def thread(key) th, irb = search(key) th end |