listen 3.3.4 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3502b7f13a7eb3801aa2ccfb12825f13ce550b6339316389a17ed6319c3c450d
4
- data.tar.gz: 433b372d311ea535f67999d23ef947dd3e4358849a60467dcf41582387d04b0f
3
+ metadata.gz: 393d712be43ee070ac7d14a4ddc090176c7f388ae2f2a7e447f674fc8875f27f
4
+ data.tar.gz: b4dfff00d893121350cb41362425a52ae4c78af20431b0567071a381d9216786
5
5
  SHA512:
6
- metadata.gz: 9a522a4498c0369db11679d60a7702e348f41442c33aa25e292807b91aa42fd7a672ed2ce77f1993c30da16b1dcae2733ecf2ddd70bbbd9a1bd89c8192483199
7
- data.tar.gz: e8f695e75d67aa62ad4f3bd5e7d237717b7f58f1e6d444099697c901b21d49ed144250eca0ef3987dd33c625de4e181b86e57f35fdc839ccdb0b6a3b3578bf75
6
+ metadata.gz: 7c7e46108e8cc30fc15289e12bedf0866ea6ef41a6798f701e16f265205ffee95a23b4526b098ae26ac910c942084d34280de31878e696e93f4d14a8f674c3ec
7
+ data.tar.gz: 3edd0902f5833038beb0b8e33b4f6f4933bea1659d51b68dbbc9a5abc63bf3ee3edd25a56309d16cd6acffead3e3be05f6ebc4d2895c893e70baff941015fcc1
@@ -93,9 +93,9 @@ module Listen
93
93
  end
94
94
 
95
95
  def _timed(title)
96
- start = Time.now.to_f
96
+ start = MonotonicTime.now
97
97
  yield
98
- diff = Time.now.to_f - start
98
+ diff = MonotonicTime.now - start
99
99
  Listen.logger.info format('%s: %.05f seconds', title, diff)
100
100
  rescue
101
101
  Listen.logger.warn "#{title} crashed: #{$ERROR_INFO.inspect}"
@@ -21,12 +21,13 @@ module Listen
21
21
 
22
22
  def _run
23
23
  loop do
24
- start = Time.now.to_f
24
+ start = MonotonicTime.now
25
25
  @polling_callbacks.each do |callback|
26
26
  callback.call(nil)
27
- nap_time = options.latency - (Time.now.to_f - start)
28
- # TODO: warn if nap_time is negative (polling too slow)
29
- sleep(nap_time) if nap_time > 0
27
+ if (nap_time = options.latency - (MonotonicTime.now - start)) > 0
28
+ # TODO: warn if nap_time is negative (polling too slow)
29
+ sleep(nap_time)
30
+ end
30
31
  end
31
32
  end
32
33
  end
@@ -28,10 +28,6 @@ module Listen
28
28
  @block&.call(*args)
29
29
  end
30
30
 
31
- def timestamp
32
- Time.now.to_f
33
- end
34
-
35
31
  def callable?
36
32
  @block
37
33
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'listen/monotonic_time'
4
+
3
5
  module Listen
4
6
  module Event
5
7
  class Processor
@@ -33,7 +35,7 @@ module Listen
33
35
 
34
36
  def _wait_until_events_calm_down
35
37
  loop do
36
- now = _timestamp
38
+ now = MonotonicTime.now
37
39
 
38
40
  # Assure there's at least latency between callbacks to allow
39
41
  # for accumulating changes
@@ -70,7 +72,7 @@ module Listen
70
72
  end
71
73
 
72
74
  def _remember_time_of_first_unprocessed_event
73
- @_remember_time_of_first_unprocessed_event ||= _timestamp
75
+ @_remember_time_of_first_unprocessed_event ||= MonotonicTime.now
74
76
  end
75
77
 
76
78
  def _reset_no_unprocessed_events
@@ -85,7 +87,7 @@ module Listen
85
87
  # returns the event or `nil` when the event_queue is closed
86
88
  def _wait_until_events
87
89
  config.event_queue.pop.tap do |_event|
88
- @_remember_time_of_first_unprocessed_event ||= _timestamp
90
+ @_remember_time_of_first_unprocessed_event ||= MonotonicTime.now
89
91
  end
90
92
  end
91
93
 
@@ -96,10 +98,6 @@ module Listen
96
98
  end
97
99
  end
98
100
 
99
- def _timestamp
100
- config.timestamp
101
- end
102
-
103
101
  # for easier testing without sleep loop
104
102
  def _process_changes(event)
105
103
  _reset_no_unprocessed_events
@@ -113,13 +111,13 @@ module Listen
113
111
  result = [hash[:modified], hash[:added], hash[:removed]]
114
112
  return if result.all?(&:empty?)
115
113
 
116
- block_start = _timestamp
114
+ block_start = MonotonicTime.now
117
115
  exception_note = " (exception)"
118
116
  ::Listen::Thread.rescue_and_log('_process_changes') do
119
117
  config.call(*result)
120
118
  exception_note = nil
121
119
  end
122
- Listen.logger.debug "Callback#{exception_note} took #{_timestamp - block_start} sec"
120
+ Listen.logger.debug "Callback#{exception_note} took #{MonotonicTime.now - block_start} sec"
123
121
  end
124
122
 
125
123
  attr_reader :config
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Listen
4
+ module MonotonicTime
5
+ class << self
6
+ if defined?(Process::CLOCK_MONOTONIC)
7
+
8
+ def now
9
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
10
+ end
11
+
12
+ elsif defined?(Process::CLOCK_MONOTONIC_RAW)
13
+
14
+ def now
15
+ Process.clock_gettime(Process::CLOCK_MONOTONIC_RAW)
16
+ end
17
+
18
+ else
19
+
20
+ def now
21
+ Time.now.to_f
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Listen
4
- VERSION = '3.3.4'
4
+ VERSION = '3.4.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: listen
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.4
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibaud Guillaume-Gentil
@@ -85,6 +85,7 @@ files:
85
85
  - lib/listen/listener.rb
86
86
  - lib/listen/listener/config.rb
87
87
  - lib/listen/logger.rb
88
+ - lib/listen/monotonic_time.rb
88
89
  - lib/listen/options.rb
89
90
  - lib/listen/queue_optimizer.rb
90
91
  - lib/listen/record.rb
@@ -101,9 +102,9 @@ metadata:
101
102
  allowed_push_host: https://rubygems.org
102
103
  bug_tracker_uri: https://github.com/guard/listen/issues
103
104
  changelog_uri: https://github.com/guard/listen/releases
104
- documentation_uri: https://www.rubydoc.info/gems/listen/3.3.4
105
+ documentation_uri: https://www.rubydoc.info/gems/listen/3.4.0
105
106
  homepage_uri: https://github.com/guard/listen
106
- source_code_uri: https://github.com/guard/listen/tree/v3.3.4
107
+ source_code_uri: https://github.com/guard/listen/tree/v3.4.0
107
108
  wiki_uri: https://github.com/guard/listen/wiki
108
109
  post_install_message:
109
110
  rdoc_options: []