Class: MakeSteps

Inherits:
Object show all
Includes:
HelperClasses
Defined in:
lib/qooxview/helpers/make_steps.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, wait = 0, &block) ⇒ MakeSteps

Returns a new instance of MakeSteps.



7
8
9
10
11
12
# File 'lib/qooxview/helpers/make_steps.rb', line 7

def initialize(session, wait = 0, &block)
  @block = block
  @oldstep = @step = 0
  @wait = wait
  session._s_data._make_step = self
end

Instance Attribute Details

#auto_updateObject

Returns the value of attribute auto_update.



4
5
6
# File 'lib/qooxview/helpers/make_steps.rb', line 4

def auto_update
  @auto_update
end

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/qooxview/helpers/make_steps.rb', line 4

def data
  @data
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/qooxview/helpers/make_steps.rb', line 4

def status
  @status
end

#stepObject

Returns the value of attribute step.



4
5
6
# File 'lib/qooxview/helpers/make_steps.rb', line 4

def step
  @step
end

Class Method Details

.make_step(session, data = nil) ⇒ Object



14
15
16
# File 'lib/qooxview/helpers/make_steps.rb', line 14

def self.make_step(session, data = nil)
  session._s_data._make_step.make_step(session, data)
end

Instance Method Details

#make_step(session, data = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/qooxview/helpers/make_steps.rb', line 36

def make_step(session, data = nil)
  #dputs_func
  dputs(3){"Oldstep in make_step: #{@oldstep}"}
  if @wait.abs > 0
    if !@thread
      dputs(3) { 'Creating new thread' }
      @thread = Thread.new {
        System.rescue_all do
          @oldstep = @step
          dputs(3) { "Calling block for step #{@step}" }
          begin
            @ret = @block.yield(session, data, @step)
          rescue LocalJumpError => e
            dputs(3) { "LocalJump: #{e.inspect}" }
            @ret = nil
          end
        end
      }
    end
    (0..@wait.abs*10).each { |i|
      dputs(4) { "Waiting #{i}" }
      sleep 0.1
      if !@thread.alive?
        dputs(3) { "Got return-value #{@ret}" }
        @thread = nil
        return reply
      end
    }
    View.reply(:auto_update, @wait) + @status.to_a
  else
    dputs(3) { "Calling block for step #{@step}" }
    begin
      @oldstep = @step
      @ret = @block.yield(session, data, @step)
    rescue LocalJumpError => e
      dputs(3) { "LocalJump: #{e.inspect}" }
      @ret = nil
    end
    reply
  end
end

#replyObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/qooxview/helpers/make_steps.rb', line 18

def reply
  #dputs_func
  dputs(3){"Oldstep: #{@oldstep} - #{@step}"}
  if @oldstep == @step && @step >= 0
    @step += 1
    dputs(3) { "Increasing step to #{@step}" }
  end
  @ret ||= []
  dputs(3) { "#{@ret} :: #{status.inspect} :: #{@auto_update.inspect}" }
  @ret.length == 0 and @ret = @status.to_a
  @ret += View.reply(:auto_update, @auto_update.to_i)
  dputs(3) { "ret is now #{@ret.inspect}" }
  @auto_update = nil if (@wait == 0 || @step == -1)
  dputs(3) { "Auto-update is #{@auto_update}" }
  @status = nil
  return @ret
end