polling 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,7 +48,7 @@ module Polling
48
48
  debug debug: opts[:debug], stime: stime
49
49
  stime
50
50
  rescue => ex
51
- $stderr.puts ex.to_s
51
+ raise ex
52
52
  end
53
53
 
54
54
  private
@@ -1,3 +1,3 @@
1
1
  module Polling
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/polling.rb CHANGED
@@ -30,9 +30,7 @@ module Polling
30
30
  end
31
31
 
32
32
  interval = Validate.value interval
33
- unless @debug
34
- e.__send__(:start_print, e.stime)
35
- end
33
+ e.__send__(:start_print, e.stime)
36
34
 
37
35
  case interval
38
36
  when Array
@@ -42,24 +40,35 @@ module Polling
42
40
  loop { exec.call interval }
43
41
  end
44
42
  rescue => ex
45
- $stderr.puts ex.message
43
+ $stderr.puts ex.to_s
46
44
  end
47
45
 
48
46
  def async_run interval=@interval, debug=false
47
+ @debug ||= debug
49
48
  e = Engine.new
50
- e.__send__(:start_print, 0)
51
- loop do
49
+
50
+ exec = lambda do |time|
52
51
  before = Time.now
53
52
  yield if block_given?
54
53
  opts = {
55
- interval: interval,
54
+ interval: time,
56
55
  before: before,
57
56
  after: Time.now,
58
- debug: debug
57
+ debug: @debug
59
58
  }
60
59
  stime = e.stime_async opts
61
60
  Sleep.exec stime
62
61
  end
62
+
63
+ interval = Validate.value interval
64
+ if interval.class == Array
65
+ raise "Can't input Array class : #{interval}"
66
+ end
67
+
68
+ e.__send__(:start_print, 0)
69
+ loop { exec.call interval }
70
+ rescue => ex
71
+ $stderr.puts ex.to_s
63
72
  end
64
73
 
65
74
  private
data/test/async_run.rb CHANGED
@@ -2,10 +2,7 @@ require File.expand_path(File.dirname(__FILE__)) + "/helper.rb"
2
2
 
3
3
  class Polling::Test < Test::Unit::TestCase
4
4
  def test_async
5
- Polling.async_run 5, true do
6
- puts "exec sleep 2"
7
- sleep 2
8
- puts Time.now
9
- end
5
+ Polling.setting debug: true
6
+ Polling.async_run 5
10
7
  end
11
8
  end
data/test/run.rb CHANGED
@@ -3,11 +3,8 @@ require File.expand_path(File.dirname(__FILE__)) + "/helper.rb"
3
3
  class Polling::Test < Test::Unit::TestCase
4
4
  def test_run
5
5
  Polling.setting offset: 5, debug: true
6
- #Polling::run [0,10,20,30,40,50] do
7
- Polling::run 5 do
8
- puts Time.now
9
- puts "exec sleep 2"
10
- sleep 2
6
+ Polling::run [0,10,20,30,40,50] do
7
+ puts "test"
11
8
  end
12
9
  end
13
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-30 00:00:00.000000000 Z
12
+ date: 2013-03-31 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: polling
15
15
  email: