Sha256: 39c3a5cf7901b10a897ba2154a83d6f1d286d18a9990132069ccd55aae14c36f

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 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

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

    end

  end # MainLoop

end # Vedeu

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.4.45 lib/vedeu/main_loop.rb