jretlang 0.2.2 → 0.2.3
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/VERSION +1 -1
- data/changelog +7 -1
- data/jretlang.gemspec +3 -2
- data/lib/jretlang/schedule.rb +44 -0
- data/lib/jretlang.rb +1 -0
- data/test/unit/test_examples.rb +15 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/changelog
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
commit
|
1
|
+
commit efcd50f516f86ba0ce53c17587e9b5edadbebaa8
|
2
|
+
Author: Gareth Reeves <greeves@drwholdings.com>
|
3
|
+
|
4
|
+
in this release (0.2.3)
|
5
|
+
-- JRL::Schedule for scheduling events to run once or repeating at some point in the future
|
6
|
+
|
7
|
+
commit 454f958b29906bfb9f9de20a8edd0dbe54685fb2
|
2
8
|
Author: Gareth Reeves <greeves@drwholdings.com>
|
3
9
|
|
4
10
|
in this release (0.2.2)
|
data/jretlang.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jretlang}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gareth Reeves"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-21}
|
13
13
|
s.description = %q{A JRuby package of jretlang}
|
14
14
|
s.email = %q{reevesg@pobox.com}
|
15
15
|
s.files = [
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
"lib/jretlang/channel.rb",
|
23
23
|
"lib/jretlang/fiber.rb",
|
24
24
|
"lib/jretlang/latch.rb",
|
25
|
+
"lib/jretlang/schedule.rb",
|
25
26
|
"readme",
|
26
27
|
"test/unit/test_examples.rb",
|
27
28
|
"test/unit/unit_test_helper.rb",
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class JRL::Schedule
|
2
|
+
class << self
|
3
|
+
def one_time( delay, name=:default, time_unit=JRL::Concurrent::TimeUnit::SECONDS, &block )
|
4
|
+
fiber(name).schedule( block, delay, time_unit )
|
5
|
+
end
|
6
|
+
|
7
|
+
def repeating( delay, interval, name=:default, time_unit=JRL::Concurrent::TimeUnit::SECONDS, &block )
|
8
|
+
fiber(name).schedule_with_fixed_delay( block, delay, interval, time_unit )
|
9
|
+
end
|
10
|
+
|
11
|
+
def dispose
|
12
|
+
@fiber_factory.dispose if @fiber_factory
|
13
|
+
@service.shutdown if @service
|
14
|
+
@fiber_map.each { |name, fiber| fiber.dispose } if @fiber_map
|
15
|
+
|
16
|
+
@fiber_factory = nil
|
17
|
+
@service = nil
|
18
|
+
@fiber_map = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def fiber_factory
|
23
|
+
@fiber_factory ||= create_fiber_factory
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_fiber_factory
|
27
|
+
@service = JRL::Concurrent::Executors.newCachedThreadPool();
|
28
|
+
JRL::Fibers::PoolFiberFactory.new(@service);
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_fiber
|
32
|
+
fiber = fiber_factory.create
|
33
|
+
fiber.start
|
34
|
+
fiber
|
35
|
+
end
|
36
|
+
|
37
|
+
def fiber( name )
|
38
|
+
name = name.to_s
|
39
|
+
@fiber_map ||= {}
|
40
|
+
@fiber_map[name] = create_fiber unless @fiber_map[name]
|
41
|
+
@fiber_map[name]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/jretlang.rb
CHANGED
data/test/unit/test_examples.rb
CHANGED
@@ -51,12 +51,27 @@ class TestChannel < Test::Unit::TestCase
|
|
51
51
|
assert l.await( 1 )
|
52
52
|
end
|
53
53
|
|
54
|
+
def test_scheduler
|
55
|
+
l = latch( 1 )
|
56
|
+
JRL::Schedule.one_time( 0.01 ) { l.count_down }
|
57
|
+
assert l.await( 1 )
|
58
|
+
JRL::Schedule.dispose
|
59
|
+
end
|
60
|
+
|
54
61
|
def test_fiber_schedule_recurring
|
55
62
|
l = latch( 5 )
|
56
63
|
@fiber.schedule_repeating( 1, 2, JRL::Concurrent::TimeUnit::MILLISECONDS ) { l.count_down }
|
57
64
|
assert l.await( 1 )
|
58
65
|
end
|
59
66
|
|
67
|
+
def test_scheduler_recurring
|
68
|
+
l = latch( 5 )
|
69
|
+
JRL::Schedule.repeating( 1, 2, :test, JRL::Concurrent::TimeUnit::MILLISECONDS ) { l.count_down }
|
70
|
+
assert l.await( 1 )
|
71
|
+
JRL::Schedule.dispose
|
72
|
+
end
|
73
|
+
|
74
|
+
|
60
75
|
def test_unsubscribe
|
61
76
|
l1 = latch( 1 )
|
62
77
|
l2 = latch( 2 )
|
metadata
CHANGED
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/jretlang/channel.rb
|
37
37
|
- lib/jretlang/fiber.rb
|
38
38
|
- lib/jretlang/latch.rb
|
39
|
+
- lib/jretlang/schedule.rb
|
39
40
|
- readme
|
40
41
|
- test/unit/test_examples.rb
|
41
42
|
- test/unit/unit_test_helper.rb
|
@@ -157,13 +158,13 @@ requirements: []
|
|
157
158
|
|
158
159
|
authors:
|
159
160
|
- Gareth Reeves
|
160
|
-
date: 2009-10-
|
161
|
+
date: 2009-10-21 05:00:00 +00:00
|
161
162
|
platform: ruby
|
162
163
|
test_files:
|
163
164
|
- test/unit/test_examples.rb
|
164
165
|
- test/unit/unit_test_helper.rb
|
165
166
|
version: !ruby/object:Gem::Version
|
166
|
-
version: 0.2.
|
167
|
+
version: 0.2.3
|
167
168
|
require_paths:
|
168
169
|
- lib
|
169
170
|
dependencies: []
|