Pulse 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/library/pulse.rb +1 -1
  2. data/library/pulse/queue.rb +25 -4
  3. metadata +3 -3
data/library/pulse.rb CHANGED
@@ -17,7 +17,7 @@ require 'pulse/script/cache'
17
17
  Thread.abort_on_exception = true
18
18
 
19
19
  module Pulse
20
- class << Version = [1,1]
20
+ class << Version = [1,2]
21
21
  def to_s; join ?. end
22
22
  end
23
23
 
@@ -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
- puts ">> #{command}"
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
- end
46
+ @thread.run if @thread and not @sleeping
47
+ end
27
48
  end
28
49
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
8
- - 1
9
- version: 1.1.1
7
+ - 2
8
+ - 0
9
+ version: 1.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mikkel Kroman