ruck-realtime 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/bin/ruck_realtime CHANGED
@@ -8,7 +8,8 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
8
8
  require "ruck"
9
9
  require "ruck/realtime"
10
10
 
11
- SHREDULER = Ruck::RealTime::RealTimeShreduler.new
11
+ @shreduler = Ruck::RealTime::RealTimeShreduler.new
12
+ @shreduler.make_convenient
12
13
 
13
14
  filenames = ARGV
14
15
  filenames.each do |filename|
@@ -19,10 +20,9 @@ filenames.each do |filename|
19
20
  end
20
21
 
21
22
  filenames.each do |filename|
22
- SHREDULER.spork(filename) do
23
- include Ruck::RealTime::ShredLocal
24
- require filename
23
+ @shreduler.spork do
24
+ load(filename, true)
25
25
  end
26
26
  end
27
27
 
28
- SHREDULER.run
28
+ @shreduler.run
data/examples/ex01.rb CHANGED
@@ -1,13 +1,15 @@
1
- spork("a") do
1
+ include Ruck
2
+
3
+ spork do
2
4
  loop do
3
- wait 1
5
+ Shred.yield 1
4
6
  puts "second"
5
7
  end
6
8
  end
7
9
 
8
- spork("b") do
10
+ spork do
9
11
  loop do
10
- wait 0.5
12
+ Shred.yield 0.5
11
13
  puts " half-second"
12
14
  end
13
15
  end
data/lib/ruck/realtime.rb CHANGED
@@ -1,2 +1,3 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), "realtime", "ruck-realtime")
2
+ require "ruck"
3
+ require File.join(File.dirname(__FILE__), "realtime", "real_time_shreduler")
@@ -0,0 +1,26 @@
1
+
2
+ module Ruck
3
+ module RealTime
4
+
5
+ # This is like the RealTimeShreduler example in the ruck README, except
6
+ # it tracks when it started so that it can detect and correct for drift
7
+ # over time.
8
+ class RealTimeShreduler < Shreduler
9
+ def run
10
+ @start_time = Time.now
11
+ @simulated_now = 0
12
+ super
13
+ end
14
+
15
+ def fast_forward(dt)
16
+ super
17
+
18
+ actual_now = Time.now - @start_time
19
+ @simulated_now += dt
20
+ if @simulated_now > actual_now
21
+ sleep(@simulated_now - actual_now)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruck-realtime}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tom Lieber"]
12
- s.date = %q{2010-07-10}
12
+ s.date = %q{2010-08-15}
13
13
  s.default_executable = %q{ruck_realtime}
14
14
  s.description = %q{ A simple real-time ruck shreduler based on Kernel#sleep. Not
15
15
  too precise, but an example of how to write a simple shreduler.
@@ -28,13 +28,13 @@ Gem::Specification.new do |s|
28
28
  "bin/ruck_realtime",
29
29
  "examples/ex01.rb",
30
30
  "lib/ruck/realtime.rb",
31
- "lib/ruck/realtime/ruck-realtime.rb",
31
+ "lib/ruck/realtime/real_time_shreduler.rb",
32
32
  "ruck-realtime.gemspec"
33
33
  ]
34
34
  s.homepage = %q{http://github.com/alltom/ruck-realtime}
35
35
  s.rdoc_options = ["--charset=UTF-8"]
36
36
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.6}
37
+ s.rubygems_version = %q{1.3.7}
38
38
  s.summary = %q{simple real-time ruck shreduler based on Kernel#sleep}
39
39
  s.test_files = [
40
40
  "examples/ex01.rb"
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
45
  s.specification_version = 3
46
46
 
47
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
48
  s.add_runtime_dependency(%q<ruck>, [">= 0"])
49
49
  else
50
50
  s.add_dependency(%q<ruck>, [">= 0"])
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruck-realtime
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 2
8
+ - 3
8
9
  - 0
9
- version: 0.2.0
10
+ version: 0.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Tom Lieber
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-10 00:00:00 -07:00
18
+ date: 2010-08-15 00:00:00 -07:00
18
19
  default_executable: ruck_realtime
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: ruck
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -46,7 +49,7 @@ files:
46
49
  - bin/ruck_realtime
47
50
  - examples/ex01.rb
48
51
  - lib/ruck/realtime.rb
49
- - lib/ruck/realtime/ruck-realtime.rb
52
+ - lib/ruck/realtime/real_time_shreduler.rb
50
53
  - ruck-realtime.gemspec
51
54
  has_rdoc: true
52
55
  homepage: http://github.com/alltom/ruck-realtime
@@ -58,23 +61,27 @@ rdoc_options:
58
61
  require_paths:
59
62
  - lib
60
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
61
65
  requirements:
62
66
  - - ">="
63
67
  - !ruby/object:Gem::Version
68
+ hash: 3
64
69
  segments:
65
70
  - 0
66
71
  version: "0"
67
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
68
74
  requirements:
69
75
  - - ">="
70
76
  - !ruby/object:Gem::Version
77
+ hash: 3
71
78
  segments:
72
79
  - 0
73
80
  version: "0"
74
81
  requirements: []
75
82
 
76
83
  rubyforge_project:
77
- rubygems_version: 1.3.6
84
+ rubygems_version: 1.3.7
78
85
  signing_key:
79
86
  specification_version: 3
80
87
  summary: simple real-time ruck shreduler based on Kernel#sleep
@@ -1,44 +0,0 @@
1
-
2
- module Ruck
3
- module RealTime
4
-
5
- class RealTimeShreduler < Shreduler
6
- def run
7
- @start_time = Time.now
8
- super
9
- end
10
-
11
- def sim_to(new_now)
12
- actual_now = Time.now
13
- simulated_now = @start_time + new_now.to_f
14
- if simulated_now > actual_now
15
- sleep(simulated_now - actual_now)
16
- end
17
-
18
- @now = new_now
19
- end
20
- end
21
-
22
- # stuff accessible in a shred
23
- module ShredLocal
24
- def now
25
- SHREDULER.now
26
- end
27
-
28
- def spork(name = "unnamed", &shred)
29
- SHREDULER.spork(name, &shred)
30
- end
31
-
32
- def wait(seconds)
33
- SHREDULER.current_shred.yield(seconds)
34
- end
35
-
36
- def finish
37
- shred = SHREDULER.current_shred
38
- SHREDULER.remove_shred shred
39
- shred.finish
40
- end
41
- end
42
-
43
- end
44
- end