ruck-realtime 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/README ADDED
@@ -0,0 +1,9 @@
1
+
2
+ A simple real-time shreduler for ruck based on Kernel#sleep.
3
+ A shreduler shredules shreds (Ruck threads). See ruck's
4
+ README for more information.
5
+
6
+ $ ruck_realtime script.rb
7
+
8
+ ruck_realtime is a Ruby script that shows you how you might
9
+ build a simple command-line interpreter with a custom shreduler.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require "rubygems"
2
+ require "rake"
3
+
4
+ begin
5
+ require "jeweler"
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ruck-realtime"
8
+ gem.email = "tom@alltom.com"
9
+ gem.homepage = "http://github.com/alltom/ruck-realtime"
10
+ gem.authors = ["Tom Lieber"]
11
+ gem.summary = %Q{simple real-time ruck shreduler based on Kernel#sleep}
12
+ gem.description = <<-EOF
13
+ A simple real-time ruck shreduler based on Kernel#sleep. Not
14
+ too precise, but an example of how to write a simple shreduler.
15
+ EOF
16
+ gem.has_rdoc = false
17
+ gem.add_dependency "ruck", ">= 0"
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/bin/ruck_realtime ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+
5
+ # for testing inside gem dir
6
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
+
8
+ require "ruck"
9
+ require "ruck/realtime"
10
+
11
+ SHREDULER = Ruck::RealTime::RealTimeShreduler.new
12
+
13
+ filenames = ARGV
14
+ filenames.each do |filename|
15
+ unless File.readable?(filename)
16
+ LOG.fatal "Cannot read file #{filename}"
17
+ exit
18
+ end
19
+ end
20
+
21
+ filenames.each do |filename|
22
+ SHREDULER.spork(filename) do
23
+ include Ruck::RealTime::ShredLocal
24
+ require filename
25
+ end
26
+ end
27
+
28
+ SHREDULER.run
data/examples/ex01.rb ADDED
@@ -0,0 +1,13 @@
1
+ spork("a") do
2
+ loop do
3
+ wait 1
4
+ puts "second"
5
+ end
6
+ end
7
+
8
+ spork("b") do
9
+ loop do
10
+ wait 0.5
11
+ puts " half-second"
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+
2
+ require File.join(File.dirname(__FILE__), "realtime", "ruck-realtime")
@@ -0,0 +1,44 @@
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
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ruck-realtime}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tom Lieber"]
12
+ s.date = %q{2010-07-10}
13
+ s.default_executable = %q{ruck_realtime}
14
+ s.description = %q{ A simple real-time ruck shreduler based on Kernel#sleep. Not
15
+ too precise, but an example of how to write a simple shreduler.
16
+ }
17
+ s.email = %q{tom@alltom.com}
18
+ s.executables = ["ruck_realtime"]
19
+ s.extra_rdoc_files = [
20
+ "README"
21
+ ]
22
+ s.files = [
23
+ ".document",
24
+ ".gitignore",
25
+ "README",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/ruck_realtime",
29
+ "examples/ex01.rb",
30
+ "lib/ruck/realtime.rb",
31
+ "lib/ruck/realtime/ruck-realtime.rb",
32
+ "ruck-realtime.gemspec"
33
+ ]
34
+ s.homepage = %q{http://github.com/alltom/ruck-realtime}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.6}
38
+ s.summary = %q{simple real-time ruck shreduler based on Kernel#sleep}
39
+ s.test_files = [
40
+ "examples/ex01.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<ruck>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<ruck>, [">= 0"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<ruck>, [">= 0"])
54
+ end
55
+ end
56
+
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruck-realtime
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
+ platform: ruby
11
+ authors:
12
+ - Tom Lieber
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-10 00:00:00 -07:00
18
+ default_executable: ruck_realtime
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: ruck
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ description: " A simple real-time ruck shreduler based on Kernel#sleep. Not\n too precise, but an example of how to write a simple shreduler.\n"
33
+ email: tom@alltom.com
34
+ executables:
35
+ - ruck_realtime
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - README
40
+ files:
41
+ - .document
42
+ - .gitignore
43
+ - README
44
+ - Rakefile
45
+ - VERSION
46
+ - bin/ruck_realtime
47
+ - examples/ex01.rb
48
+ - lib/ruck/realtime.rb
49
+ - lib/ruck/realtime/ruck-realtime.rb
50
+ - ruck-realtime.gemspec
51
+ has_rdoc: true
52
+ homepage: http://github.com/alltom/ruck-realtime
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.6
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: simple real-time ruck shreduler based on Kernel#sleep
81
+ test_files:
82
+ - examples/ex01.rb