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 +4 -4
- data/lib/listen/adapter/base.rb +2 -2
- data/lib/listen/adapter/polling.rb +5 -4
- data/lib/listen/event/config.rb +0 -4
- data/lib/listen/event/processor.rb +7 -9
- data/lib/listen/monotonic_time.rb +27 -0
- data/lib/listen/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 393d712be43ee070ac7d14a4ddc090176c7f388ae2f2a7e447f674fc8875f27f
|
4
|
+
data.tar.gz: b4dfff00d893121350cb41362425a52ae4c78af20431b0567071a381d9216786
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c7e46108e8cc30fc15289e12bedf0866ea6ef41a6798f701e16f265205ffee95a23b4526b098ae26ac910c942084d34280de31878e696e93f4d14a8f674c3ec
|
7
|
+
data.tar.gz: 3edd0902f5833038beb0b8e33b4f6f4933bea1659d51b68dbbc9a5abc63bf3ee3edd25a56309d16cd6acffead3e3be05f6ebc4d2895c893e70baff941015fcc1
|
data/lib/listen/adapter/base.rb
CHANGED
@@ -93,9 +93,9 @@ module Listen
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def _timed(title)
|
96
|
-
start =
|
96
|
+
start = MonotonicTime.now
|
97
97
|
yield
|
98
|
-
diff =
|
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 =
|
24
|
+
start = MonotonicTime.now
|
25
25
|
@polling_callbacks.each do |callback|
|
26
26
|
callback.call(nil)
|
27
|
-
nap_time = options.latency - (
|
28
|
-
|
29
|
-
|
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
|
data/lib/listen/event/config.rb
CHANGED
@@ -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 =
|
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 ||=
|
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 ||=
|
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 =
|
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 #{
|
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
|
data/lib/listen/version.rb
CHANGED
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.
|
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.
|
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.
|
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: []
|