wisper-async 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - '1.9.2'
4
+ - '1.9.3'
5
+ - jruby-19mode
6
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,60 @@
1
+ # Wisper Async (Experimental)
2
+
3
+ Extends [Wisper](https://github.com/krisleech/wisper) with async broadcasting
4
+ of events.
5
+
6
+ [![Code Climate](https://codeclimate.com/github/krisleech/wisper-async.png)](https://codeclimate.com/github/krisleech/wisper-async)
7
+ [![Build Status](https://travis-ci.org/krisleech/wisper-async.png?branch=master)](https://travis-ci.org/krisleech/wisper-async)
8
+
9
+ ## Installation
10
+
11
+ ```ruby
12
+ gem 'wisper-async'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ By passing `async` option when adding listeners any events broadcast to that
18
+ listener will happen in its own thread.
19
+
20
+ ```ruby
21
+ my_publisher.add_subscriber(MySubscriber.new, :async => true)
22
+ ```
23
+
24
+ This leans on Celluloid.
25
+
26
+ The listener is transparently turned in to a Celluloid Actor.
27
+
28
+ Please refer to [Celluloid](https://github.com/celluloid/celluloid/wiki)
29
+ for more information, particually the
30
+ [Gotchas](https://github.com/celluloid/celluloid/wiki/Gotchas).
31
+
32
+ ## Compatibility
33
+
34
+ Tested with 1.9.x on MRI, JRuby and Rubinius.
35
+ See the [build status](https://travis-ci.org/krisleech/wisper-async) for details.
36
+
37
+ ## License
38
+
39
+ Copyright (c) 2013 Kris Leech
40
+
41
+ MIT License
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ "Software"), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
57
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
58
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
59
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
60
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ require 'celluloid/autostart'
2
+ require 'wisper'
3
+ require "wisper/async/version"
4
+ require "wisper/async/listener"
5
+
6
+ module Wisper
7
+ class ObjectRegistration
8
+ attr_reader :async
9
+
10
+ def initialize(listener, options)
11
+ super(listener, options)
12
+ @async = options.fetch(:async, false)
13
+ end
14
+
15
+ def broadcast(event, *args)
16
+ method_to_call = map_event_to_method(event)
17
+ if should_broadcast?(event) && listener.respond_to?(method_to_call)
18
+ unless async
19
+ listener.public_send(method_to_call, *args)
20
+ else
21
+ Async::Listener.new(listener, method_to_call).async.public_send(method_to_call, *args)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,27 @@
1
+ module Wisper
2
+ module Async
3
+ class Listener
4
+ include Celluloid
5
+
6
+ attr_reader :listener, :event_method
7
+
8
+ def initialize(listener, event_method)
9
+ @listener = listener
10
+ @event_method = event_method.to_sym
11
+ end
12
+
13
+ def method_missing(method, *args, &block)
14
+ if listener.respond_to?(method)
15
+ if method == event_method
16
+ listener.public_send(method, *args, &block)
17
+ terminate
18
+ else
19
+ listener.public_send(method, *args, &block)
20
+ end
21
+ else
22
+ super(method, *args, &block)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Wisper
2
+ module Async
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ class MyService
4
+ include Wisper
5
+
6
+ def execute
7
+ broadcast('success', self)
8
+ end
9
+ end
10
+
11
+ # help me...
12
+ $global = nil
13
+
14
+ class MyListener
15
+ def success(command)
16
+ $global = Thread.current.object_id
17
+ end
18
+ end
19
+
20
+ describe Wisper do
21
+
22
+ it 'broadcasts event in different thread' do
23
+ listener = MyListener.new
24
+
25
+ command = MyService.new
26
+
27
+ command.add_listener(listener, :async => true)
28
+
29
+ command.execute
30
+ sleep(1) # seriously...
31
+ $global.should_not == Thread.current.object_id
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'wisper'
5
+ require 'wisper/async'
6
+
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ config.order = 'random'
12
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wisper/async/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wisper-async"
8
+ spec.version = Wisper::Async::VERSION
9
+ spec.authors = ["Kris Leech"]
10
+ spec.email = ["kris.leech@gmail.com"]
11
+ spec.description = "Adds async broadcasting of events to Wisper"
12
+ spec.summary = "Adds async broadcasting of events to Wisper"
13
+ spec.homepage = "https://github.com/krisleech/wisper-async"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'wisper', '~>1.0'
22
+ spec.add_dependency 'celluloid'
23
+
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'simplecov'
28
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisper-async
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kris Leech
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: wisper
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: celluloid
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Adds async broadcasting of events to Wisper
111
+ email:
112
+ - kris.leech@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - .travis.yml
120
+ - Gemfile
121
+ - README.md
122
+ - Rakefile
123
+ - lib/wisper/async.rb
124
+ - lib/wisper/async/listener.rb
125
+ - lib/wisper/async/version.rb
126
+ - spec/lib/wisper/async_spec.rb
127
+ - spec/spec_helper.rb
128
+ - wisper-async.gemspec
129
+ homepage: https://github.com/krisleech/wisper-async
130
+ licenses:
131
+ - MIT
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 1.8.24
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Adds async broadcasting of events to Wisper
154
+ test_files:
155
+ - spec/lib/wisper/async_spec.rb
156
+ - spec/spec_helper.rb
157
+ has_rdoc: