Sha256: 3cbfbc75f7d9320234c923ad7ea7cf9275a3e9b611168719241f84bf63a22847

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

module Vedeu

  module Runtime

    # 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

          Vedeu.trigger(:_refresh_cursor_, Vedeu.focus)

          while @loop
            Vedeu.refresh

            yield

            safe_exit_point!
          end
        rescue Vedeu::Error::Interrupt
          Vedeu.log(type:    :info,
                    message: 'Vedeu execution interrupted, exiting.'.freeze)
        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 [Vedeu::Error::Interrupt] When we wish to terminate
        #   the running application.
        # @return [void]
        def safe_exit_point!
          fail Vedeu::Error::Interrupt if @started && !@loop
        end

        # :nocov:

      end # Eigenclass

    end # MainLoop

  end # Runtime

end # Vedeu

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vedeu-0.6.34 lib/vedeu/runtime/main_loop.rb
vedeu-0.6.33 lib/vedeu/runtime/main_loop.rb
vedeu-0.6.32 lib/vedeu/runtime/main_loop.rb
vedeu-0.6.31 lib/vedeu/runtime/main_loop.rb
vedeu-0.6.30 lib/vedeu/runtime/main_loop.rb
vedeu-0.6.29 lib/vedeu/runtime/main_loop.rb