Pulse 1.1.1 → 1.2.0
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.
- data/library/pulse.rb +1 -1
- data/library/pulse/queue.rb +25 -4
- metadata +3 -3
data/library/pulse.rb
CHANGED
data/library/pulse/queue.rb
CHANGED
@@ -2,8 +2,15 @@
|
|
2
2
|
|
3
3
|
module Pulse
|
4
4
|
class Queue
|
5
|
+
|
6
|
+
SleepDuration = 2
|
7
|
+
Timelapse = 4
|
8
|
+
Amount = 3
|
9
|
+
|
10
|
+
# Sleep SleepDuration if the last Amount messages was sent with a TimeBound second difference.
|
11
|
+
|
5
12
|
def initialize
|
6
|
-
@queue = []
|
13
|
+
@queue, @history, @sleeping = [], (0..Amount).map { |i| 0 }, false
|
7
14
|
end
|
8
15
|
|
9
16
|
def process socket
|
@@ -12,17 +19,31 @@ module Pulse
|
|
12
19
|
|
13
20
|
while @thread.alive?
|
14
21
|
if command = @queue.shift
|
15
|
-
|
22
|
+
|
23
|
+
@history.shift and @history << Time.now.to_i
|
24
|
+
|
25
|
+
if spam?
|
26
|
+
@sleeping = true
|
27
|
+
sleep SleepDuration
|
28
|
+
@sleeping = false
|
29
|
+
end
|
30
|
+
|
16
31
|
@socket.write "#{command}\n"
|
32
|
+
|
33
|
+
puts ">> #{command}"
|
17
34
|
else
|
18
35
|
Thread.stop
|
19
36
|
end
|
20
37
|
end
|
21
38
|
end
|
22
39
|
|
40
|
+
def spam?
|
41
|
+
@history.select { |time| time >= Time.now.to_i - Timelapse }.count >= Amount
|
42
|
+
end
|
43
|
+
|
23
44
|
def << command
|
24
45
|
@queue << command
|
25
|
-
@thread.run if @thread
|
26
|
-
|
46
|
+
@thread.run if @thread and not @sleeping
|
47
|
+
end
|
27
48
|
end
|
28
49
|
end
|