em_alldone 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG.rdoc +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +27 -0
- data/README.rdoc +70 -0
- data/em_alldone.gemspec +22 -0
- data/lib/em_alldone.rb +37 -0
- data/spec/em_alldone_spec.rb +55 -0
- data/spec/spec_helper.rb +7 -0
- metadata +60 -0
data/.gitignore
ADDED
data/CHANGELOG.rdoc
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
bacon (1.1.0)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
em-spec (0.2.6)
|
7
|
+
bacon
|
8
|
+
eventmachine
|
9
|
+
rspec (> 2.6.0)
|
10
|
+
test-unit
|
11
|
+
eventmachine (1.0.3)
|
12
|
+
rspec (2.8.0)
|
13
|
+
rspec-core (~> 2.8.0)
|
14
|
+
rspec-expectations (~> 2.8.0)
|
15
|
+
rspec-mocks (~> 2.8.0)
|
16
|
+
rspec-core (2.8.0)
|
17
|
+
rspec-expectations (2.8.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.8.0)
|
20
|
+
test-unit (2.4.7)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
em-spec
|
27
|
+
rspec
|
data/README.rdoc
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
= EmAlldone
|
2
|
+
|
3
|
+
http://github.com/thoughtless/em_alldone
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Not a genuine Deferrable in that it doesn't include EM::Deferrable. Callbacks
|
8
|
+
set will be run when all the passed in deferrables have completed with either
|
9
|
+
success or failure. Doesn't support errbacks.
|
10
|
+
|
11
|
+
== SYNOPSIS:
|
12
|
+
|
13
|
+
A quick example:
|
14
|
+
|
15
|
+
require 'em_alldone'
|
16
|
+
|
17
|
+
d1 = EM::DefaultDeferrable.new
|
18
|
+
d2 = EM::DefaultDeferrable.new
|
19
|
+
EmAlldone.new(d1, d2) do
|
20
|
+
puts "All done"
|
21
|
+
end
|
22
|
+
d1.succeed # Nothing happens
|
23
|
+
d2.succeed # Prints out "All done"
|
24
|
+
|
25
|
+
|
26
|
+
== REQUIREMENTS:
|
27
|
+
|
28
|
+
Although there are no strict requirements, this gem is written to work with
|
29
|
+
Ruby EventMachine and will likely be of little value if you don't have that
|
30
|
+
gem installed and required.
|
31
|
+
|
32
|
+
|
33
|
+
== INSTALL:
|
34
|
+
|
35
|
+
TODO
|
36
|
+
|
37
|
+
|
38
|
+
== RUNNING THE SPECS:
|
39
|
+
|
40
|
+
bundle exec rspec spec
|
41
|
+
|
42
|
+
|
43
|
+
== TODO:
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
== LICENSE:
|
48
|
+
|
49
|
+
(The MIT License)
|
50
|
+
|
51
|
+
Copyright (c) 2012 Poll Everywhere, Paul Cortens
|
52
|
+
|
53
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
54
|
+
a copy of this software and associated documentation files (the
|
55
|
+
'Software'), to deal in the Software without restriction, including
|
56
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
57
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
58
|
+
permit persons to whom the Software is furnished to do so, subject to
|
59
|
+
the following conditions:
|
60
|
+
|
61
|
+
The above copyright notice and this permission notice shall be
|
62
|
+
included in all copies or substantial portions of the Software.
|
63
|
+
|
64
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
65
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
66
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
67
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
68
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
69
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
70
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/em_alldone.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
require "em_alldone" # To dynamically load the version string
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "em_alldone"
|
7
|
+
s.version = EmAlldone::Version::STRING
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Paul Cortens"]
|
10
|
+
s.email = "paul@thoughtless.ca"
|
11
|
+
s.homepage = "http://github.com/thoughtless/em_alldone"
|
12
|
+
s.summary = "em_alldone#{EmAlldone::Version::STRING}"
|
13
|
+
s.description = "Provides a way to execute a callback when all of a set of deferrables complete."
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.extra_rdoc_files = [ 'README.rdoc', 'CHANGELOG.rdoc']
|
20
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
21
|
+
s.require_path = "lib"
|
22
|
+
end
|
data/lib/em_alldone.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Not a genuine Deferrable in that it doesn't include EM::Deferrable. Callbacks
|
2
|
+
# set will be run when all the passed in deferrables have completed with either
|
3
|
+
# success or failure. Doesn't support errbacks.
|
4
|
+
class EmAlldone
|
5
|
+
module Version # :nodoc:
|
6
|
+
STRING = '0.0.1'
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(*deferrables, &block)
|
10
|
+
deferrables = deferrables.flatten
|
11
|
+
raise ArgumentError, "Must provide at least one argument" unless deferrables.size > 0
|
12
|
+
deferrables.each do |d|
|
13
|
+
raise ArgumentError, "All arguments must be deferrables, but #{d.inspect} doesn't." unless d.respond_to?(:callback) && d.respond_to?(:errback)
|
14
|
+
end
|
15
|
+
|
16
|
+
@deferrable = deferrables[-1]
|
17
|
+
|
18
|
+
if deferrables.size > 1
|
19
|
+
@recurse = EmAlldone.new deferrables[0...-1]
|
20
|
+
end
|
21
|
+
|
22
|
+
self.callback &block if block
|
23
|
+
end
|
24
|
+
|
25
|
+
def callback &block
|
26
|
+
current_proc = Proc.new do
|
27
|
+
@deferrable.callback &block
|
28
|
+
@deferrable.errback &block
|
29
|
+
end
|
30
|
+
|
31
|
+
if @recurse
|
32
|
+
@recurse.callback ¤t_proc
|
33
|
+
else
|
34
|
+
current_proc.call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'em_alldone'
|
3
|
+
|
4
|
+
describe EmAlldone do
|
5
|
+
describe '.new' do
|
6
|
+
it 'raises an error if no deferrables are passed as arguments' do
|
7
|
+
lambda {
|
8
|
+
EmAlldone.new
|
9
|
+
}.should raise_error ArgumentError, /at least one/
|
10
|
+
end
|
11
|
+
|
12
|
+
it "raises an error if the argument isn't a deferrables" do
|
13
|
+
lambda {
|
14
|
+
EmAlldone.new 1, 2, 3
|
15
|
+
}.should raise_error ArgumentError, /must be deferrables/
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'accepts a callback' do
|
19
|
+
EmAlldone.new(
|
20
|
+
EM::DefaultDeferrable.new.tap {|d| d.succeed }
|
21
|
+
) { @it_ran = true }
|
22
|
+
@it_ran.should be_true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "all the deferrables pass" do
|
27
|
+
let(:d1) { EM::DefaultDeferrable.new.tap {|d| d.succeed } }
|
28
|
+
let(:d2) { EM::DefaultDeferrable.new.tap {|d| d.succeed } }
|
29
|
+
subject { EmAlldone.new(d1, d2) }
|
30
|
+
it "runs the call back" do
|
31
|
+
subject.callback { @it_ran = true }
|
32
|
+
@it_ran.should be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "a deferrable doesn't finish" do
|
37
|
+
let(:d1) { EM::DefaultDeferrable.new.tap {|d| d.succeed } }
|
38
|
+
let(:d2) { EM::DefaultDeferrable.new }
|
39
|
+
subject { EmAlldone.new(d1, d2) }
|
40
|
+
it "does not run the call back" do
|
41
|
+
subject.callback { @it_ran = true }
|
42
|
+
@it_ran.should be_nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "all the deferrables fail" do
|
47
|
+
let(:d1) { EM::DefaultDeferrable.new.tap {|d| d.fail } }
|
48
|
+
let(:d2) { EM::DefaultDeferrable.new.tap {|d| d.fail } }
|
49
|
+
subject { EmAlldone.new(d1, d2) }
|
50
|
+
it "runs the call back" do
|
51
|
+
subject.callback { @it_ran = true }
|
52
|
+
@it_ran.should be_true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'em_alldone'
|
3
|
+
require 'em-spec/rspec'
|
4
|
+
|
5
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
6
|
+
# # in spec/support/ and its subdirectories.
|
7
|
+
Dir[File.join(File.expand_path("..", __FILE__), "support/**/*.rb")].each {|f| require f}
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em_alldone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paul Cortens
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Provides a way to execute a callback when all of a set of deferrables
|
15
|
+
complete.
|
16
|
+
email: paul@thoughtless.ca
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.rdoc
|
21
|
+
- CHANGELOG.rdoc
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- CHANGELOG.rdoc
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- README.rdoc
|
28
|
+
- em_alldone.gemspec
|
29
|
+
- lib/em_alldone.rb
|
30
|
+
- spec/em_alldone_spec.rb
|
31
|
+
- spec/spec_helper.rb
|
32
|
+
homepage: http://github.com/thoughtless/em_alldone
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.8.28
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: em_alldone0.0.1
|
58
|
+
test_files:
|
59
|
+
- spec/em_alldone_spec.rb
|
60
|
+
- spec/spec_helper.rb
|