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