Sha256: c776931e6f1f1afb4215543bd3c570380c5d145ee83b0755f4df8ae0b13584d6

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

module Vedeu

  # Provides the main loop for a Vedeu application.
  #
  # @api private
  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 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

      # 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 VedeuInterrupt if @started && !@loop
      end

    end

  end # MainLoop

end # Vedeu

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
vedeu-0.4.44 lib/vedeu/main_loop.rb
vedeu-0.4.43 lib/vedeu/main_loop.rb
vedeu-0.4.42 lib/vedeu/main_loop.rb
vedeu-0.4.41 lib/vedeu/main_loop.rb
vedeu-0.4.40 lib/vedeu/main_loop.rb
vedeu-0.4.39 lib/vedeu/main_loop.rb
vedeu-0.4.38 lib/vedeu/main_loop.rb
vedeu-0.4.37 lib/vedeu/main_loop.rb
vedeu-0.4.36 lib/vedeu/main_loop.rb