Class: Vedeu::MainLoop

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/main_loop.rb

Overview

Provides the main loop for a Vedeu application.

Each time Vedeu starts one cycle in the application loop, it triggers the ‘:tick` event. A completion of that cycle will trigger `:tock`. This can be used by the client application for timing amongst other things.

Class Method Summary collapse

Class Method Details

.safe_exit_point!void (private)

This method returns an undefined value.

Check the application has started and we wish to continue running.

Raises:

  • (VedeuInterrupt)

    When we wish to terminate the running application.



47
48
49
50
51
52
53
54
55
# File 'lib/vedeu/main_loop.rb', line 47

def self.safe_exit_point!
  if @started && !@loop
    fail VedeuInterrupt

  else
    Vedeu.trigger(:tock)

  end
end

.start!(&block) ⇒ void

This method returns an undefined value.

Start the main loop.

Parameters:

  • block (Proc)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vedeu/main_loop.rb', line 19

def self.start!(&block)
  @started = true
  @loop    = true

  while(@loop) do
    Vedeu.trigger(:tick)

    yield

    safe_exit_point!
  end
rescue VedeuInterrupt

end

.stop!void

This method returns an undefined value.

Signal that we wish to terminate the running application.



37
38
39
# File 'lib/vedeu/main_loop.rb', line 37

def self.stop!
  @loop = false
end