lounger 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lounger.rb +39 -8
- data/lib/lounger/version.rb +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 11ac13fa2d6f6eb0b5154ed80d986d867764e151
         | 
| 4 | 
            +
              data.tar.gz: 41ceb2e39c847fff0b12de6d374db13d6ded06e9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d04aa8779babc1c568af75bb6d49e055da458805e10b4938354f31499b6f6f2cbc5eea03daa6c94e5d132f1f12e7329b82b0631945726d2c0d1347264945acc5
         | 
| 7 | 
            +
              data.tar.gz: f67a0e8d973557924b912fc348c89a41416735fb527bd65388a2aa917cb481414288690eb43907f5cfa2bf855398173248002041f3b615558b4773371d2e2b31
         | 
    
        data/lib/lounger.rb
    CHANGED
    
    | @@ -4,26 +4,57 @@ class Lounger | |
| 4 4 | 
             
              SIGNALS = ["INT", "TERM", "EXIT", "USR1", "QUIT"]
         | 
| 5 5 |  | 
| 6 6 | 
             
              def initialize(include_signals: [], exclude_signals: [])
         | 
| 7 | 
            -
                @lock | 
| 8 | 
            -
                @condition | 
| 7 | 
            +
                @lock            = Mutex.new
         | 
| 8 | 
            +
                @condition       = ConditionVariable.new
         | 
| 9 | 
            +
                @pending_signals = 0
         | 
| 10 | 
            +
                @buffer          = []
         | 
| 11 | 
            +
                @idle            = false
         | 
| 9 12 |  | 
| 10 | 
            -
                (SIGNALS + include_signals - exclude_signals).each do | | 
| 11 | 
            -
                  Signal.trap( | 
| 13 | 
            +
                (SIGNALS + include_signals - exclude_signals).each do |s|
         | 
| 14 | 
            +
                  prev = Signal.trap(s) do
         | 
| 15 | 
            +
                    @condition.signal
         | 
| 16 | 
            +
                    prev.call unless prev.is_a?(String)
         | 
| 17 | 
            +
                  end
         | 
| 12 18 | 
             
                end
         | 
| 13 19 | 
             
              end
         | 
| 14 20 |  | 
| 15 | 
            -
              def idle
         | 
| 16 | 
            -
                 | 
| 21 | 
            +
              def idle(ignore_pending: false)
         | 
| 22 | 
            +
                result = nil
         | 
| 23 | 
            +
                @lock.synchronize do
         | 
| 24 | 
            +
                  @pending_signals = 0 if ignore_pending
         | 
| 25 | 
            +
                  @idle = true
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  if @pending_signals > 0
         | 
| 28 | 
            +
                    @pending_signals -= 1
         | 
| 29 | 
            +
                  else
         | 
| 30 | 
            +
                    @condition.wait(@lock)
         | 
| 31 | 
            +
                    @pending_signals -= 1
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  @idle = false
         | 
| 35 | 
            +
                  result = @buffer.shift
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                return result
         | 
| 17 39 | 
             
              end
         | 
| 18 40 |  | 
| 19 | 
            -
              def  | 
| 20 | 
            -
                @ | 
| 41 | 
            +
              def idle?
         | 
| 42 | 
            +
                return @idle
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              def wakeup!(value = nil)
         | 
| 46 | 
            +
                @lock.synchronize do
         | 
| 47 | 
            +
                  @pending_signals += 1
         | 
| 48 | 
            +
                  @buffer << value
         | 
| 49 | 
            +
                  @condition.signal
         | 
| 50 | 
            +
                end
         | 
| 21 51 | 
             
              end
         | 
| 22 52 |  | 
| 23 53 | 
             
              def self.idle
         | 
| 24 54 | 
             
                Lounger.new.idle
         | 
| 25 55 | 
             
              end
         | 
| 26 56 |  | 
| 57 | 
            +
              alias_method :waiting?, :idle?
         | 
| 27 58 | 
             
              alias_method :wait, :idle
         | 
| 28 59 | 
             
              alias_method :signal, :wakeup!
         | 
| 29 60 | 
             
            end
         | 
    
        data/lib/lounger/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: lounger
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Groza Sergiu
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2017-11-28 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 92 92 | 
             
                  version: '0'
         | 
| 93 93 | 
             
            requirements: []
         | 
| 94 94 | 
             
            rubyforge_project: 
         | 
| 95 | 
            -
            rubygems_version: 2. | 
| 95 | 
            +
            rubygems_version: 2.6.10
         | 
| 96 96 | 
             
            signing_key: 
         | 
| 97 97 | 
             
            specification_version: 4
         | 
| 98 98 | 
             
            summary: A simple Ruby gem for current thread idling
         |