em-batch 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (10) hide show
  1. data/.document +5 -0
  2. data/Gemfile +13 -0
  3. data/Gemfile.lock +20 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.md +86 -0
  6. data/Rakefile +29 -0
  7. data/VERSION +1 -0
  8. data/lib/em-batch.rb +58 -0
  9. data/test +28 -0
  10. metadata +105 -0
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+
5
+ gem "callback-batch", ">= 0.1.0"
6
+ gem "eventmachine", ">= 0"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "bundler", ">= 1.0.0"
12
+ gem "jeweler", ">= 1.5.2"
13
+ end
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ callback-batch (0.1.0)
5
+ eventmachine (1.0.0.beta.3)
6
+ git (1.2.5)
7
+ jeweler (1.6.4)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ rake (0.9.2)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (>= 1.0.0)
18
+ callback-batch (>= 0.1.0)
19
+ eventmachine
20
+ jeweler (>= 1.5.2)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,86 @@
1
+ EventMachine Batch
2
+ ==================
3
+
4
+ **em-batch** provides ability to run more callbacked methods
5
+ of single or more objects by elegant, readable and transparent way
6
+ in a linear sequence, so subsequently in single batch.
7
+
8
+ Two classes are available, *sequencer* and more general *batch*.
9
+ Batch supports more objects in one batch, sequencer is syntactic
10
+ sugar in fact for single object.
11
+
12
+ It's implementation of the [callback-batch][9] gem, but customized
13
+ for running in [EventMachine][8] environment, so calls will be fully
14
+ multiplexed to more subsequent ticks.
15
+
16
+ See some trivial examples:
17
+
18
+ require "eventmachine"
19
+ require "callback-batch"
20
+
21
+ class Foo
22
+ def foo1
23
+ yield :foo1
24
+ end
25
+ def foo2
26
+ yield :foo2
27
+ end
28
+ end
29
+
30
+ class Bar
31
+ def bar1
32
+ yield :bar1
33
+ end
34
+ def bar2
35
+ yield :bar2
36
+ end
37
+ end
38
+
39
+
40
+ EM::run do
41
+
42
+ ### Sequencer
43
+
44
+ s = CallbackSequencer::new(Foo::new)
45
+ s.foo1
46
+ s.foo2
47
+
48
+ s.execute do # now will be both methods executed
49
+ p s.results # will contain [:foo1, :foo2]
50
+ end
51
+
52
+ ### Batch
53
+
54
+ s = CallbackBatch::new
55
+ f = Foo::new
56
+ b = Bar::new
57
+
58
+ s.take(f).foo1
59
+ s.take(b).bar2
60
+
61
+ s.execute do # now will be both methods executed
62
+ p s.results # will contain [:foo1, :bar2]
63
+ end
64
+
65
+ end
66
+
67
+ Contributing
68
+ ------------
69
+
70
+ 1. Fork it.
71
+ 2. Create a branch (`git checkout -b 20101220-my-change`).
72
+ 3. Commit your changes (`git commit -am "Added something"`).
73
+ 4. Push to the branch (`git push origin 20101220-my-change`).
74
+ 5. Create an [Issue][9] with a link to your branch.
75
+ 6. Enjoy a refreshing Diet Coke and wait.
76
+
77
+
78
+ Copyright
79
+ ---------
80
+
81
+ Copyright © 2011 [Martin Kozák][10]. See `LICENSE.txt` for
82
+ further details.
83
+
84
+ [8]: http://rubyeventmachine.com/
85
+ [9]: http://github.com/martinkozak/callback-batch/issues
86
+ [10]: http://www.martinkozak.net/
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+
13
+ require 'rake'
14
+ require 'jeweler'
15
+
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "em-batch"
19
+ gem.homepage = "http://github.com/martinkozak/em-batch"
20
+ gem.license = "MIT"
21
+ gem.summary = "Provides ability to run more callbacked methods backed by EventMachine of single or more objects by elegant, readable and transparent way in a linear sequence, so subsequently in single batch."
22
+ gem.email = "martinkozak@martinkozak.net"
23
+ gem.authors = ["Martin Kozák"]
24
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
25
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
26
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
27
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
+
4
+ require "callback-batch"
5
+ require "eventmachine"
6
+
7
+ ##
8
+ # Core eventmachine module.
9
+ # @see http:///www.eventmachine.com/
10
+ #
11
+
12
+ module EM
13
+
14
+ ##
15
+ # Sequencer for running batches upon single object.
16
+ #
17
+
18
+ class Sequencer < CallbackSequencer
19
+
20
+ ##
21
+ # Constructor.
22
+ # @param [Object] target target object
23
+ #
24
+
25
+ def initialize(target)
26
+ super
27
+ @batch = Batch::new
28
+ end
29
+
30
+ end
31
+
32
+ ##
33
+ # Batch of the objects and method names with arguments for runninng
34
+ # on a series.
35
+ #
36
+
37
+ class Batch < CallbackBatch
38
+
39
+ ##
40
+ # Schedules next tick execution.
41
+ # @yield
42
+ #
43
+
44
+ def schedule_tick(&block)
45
+ EM::next_tick(&block)
46
+ end
47
+
48
+ ##
49
+ # Schedules next call execution.
50
+ # @yield
51
+ #
52
+
53
+ def schedule_call(&block)
54
+ EM::next_tick(&block)
55
+ end
56
+
57
+ end
58
+ end
data/test ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: utf-8
3
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
4
+
5
+ $:.push("./lib")
6
+ $:.unshift("./lib")
7
+
8
+ require "eventmachine"
9
+ require "em-batch"
10
+
11
+ class Foo
12
+ def b1(&block)
13
+ yield :b1
14
+ end
15
+ def b2(&block)
16
+ yield :b2
17
+ end
18
+ end
19
+
20
+ EM::run do
21
+ q = EM::Sequencer::new(Foo::new)
22
+ q.b1
23
+ q.b2
24
+
25
+ q.execute! do
26
+ p q.results
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-batch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Martin Kozák
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: callback-batch
16
+ requirement: &23538100 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *23538100
25
+ - !ruby/object:Gem::Dependency
26
+ name: eventmachine
27
+ requirement: &23537140 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *23537140
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &23515860 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *23515860
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &23514640 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.2
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *23514640
58
+ description:
59
+ email: martinkozak@martinkozak.net
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files:
63
+ - LICENSE.txt
64
+ - README.md
65
+ files:
66
+ - .document
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - VERSION
73
+ - lib/em-batch.rb
74
+ - test
75
+ homepage: http://github.com/martinkozak/em-batch
76
+ licenses:
77
+ - MIT
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: -1254289393403648479
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.11
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Provides ability to run more callbacked methods backed by EventMachine of
103
+ single or more objects by elegant, readable and transparent way in a linear sequence,
104
+ so subsequently in single batch.
105
+ test_files: []