Sha256: 8d4b8fce3f20921b688e6753569b5cabeeb46f437f5cc38b54ff91102510669b

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

module Vedeu

  # Provides the main loop for a Vedeu application.
  #
  class MainLoop

    trap('SIGTERM') { stop! }
    trap('TERM')    { stop! }
    trap('INT')     { stop! }

    class << self

      # :nocov:
      # Start the main loop.
      #
      # @return [void]
      # @yieldreturn [void] The client application.
      def start!
        @started = true
        @loop    = true

        while @loop
          yield

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

      # Signal that we wish to terminate the running application.
      #
      # @return [void]
      def stop!
        @loop = false
      end

      # :nocov:
      # Check the application has started and we wish to continue running.
      #
      # @raise [VedeuInterrupt] When we wish to terminate the running
      #   application.
      # @return [void]
      def safe_exit_point!
        fail Vedeu::VedeuInterrupt if @started && !@loop
      end
      # :nocov:

    end # Eigenclass

  end # MainLoop

end # Vedeu

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vedeu-0.4.62 lib/vedeu/main_loop.rb
vedeu-0.4.61 lib/vedeu/main_loop.rb
vedeu-0.4.60 lib/vedeu/main_loop.rb
vedeu-0.4.59 lib/vedeu/main_loop.rb
vedeu-0.4.58 lib/vedeu/main_loop.rb