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

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.



44
45
46
47
48
49
50
51
52
# File 'lib/vedeu/main_loop.rb', line 44

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

  else
    Vedeu.trigger(:tock, Time.now.to_f)

  end
end

.start!void

This method returns an undefined value.

:nocov: Start the main loop.

Yield Returns:

  • (void)

    The client application.



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

def self.start!
  @started = true
  @loop    = true

  while @loop
    yield

    safe_exit_point!
  end
rescue VedeuInterrupt
  Vedeu.log(type: :debug, message: 'Vedeu execution interrupted, exiting.')
end

.stop!void

This method returns an undefined value.

Signal that we wish to terminate the running application.



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

def self.stop!
  @loop = false
end