async 0.9.1

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.
@@ -0,0 +1,95 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'benchmark'
22
+
23
+ RSpec.describe Async::Task do
24
+ let(:reactor) {Async::Reactor.new}
25
+
26
+ describe '#stop!' do
27
+ it "can be stopped" do
28
+ state = nil
29
+
30
+ task = reactor.async do |task|
31
+ state = :started
32
+ task.sleep(10)
33
+ state = :finished
34
+ end
35
+
36
+ task.stop!
37
+
38
+ expect(state).to be == :started
39
+ end
40
+ end
41
+
42
+ describe '#sleep' do
43
+ let(:duration) {0.01}
44
+
45
+ it "can sleep for the requested duration" do
46
+ state = nil
47
+
48
+ task = reactor.async do |task|
49
+ task.sleep(duration)
50
+ state = :finished
51
+ end
52
+
53
+ time = Benchmark.realtime do
54
+ reactor.run
55
+ end
56
+
57
+ expect(time).to be_within(50).percent_of(duration)
58
+ expect(state).to be == :finished
59
+ end
60
+ end
61
+
62
+ describe '#timeout' do
63
+ it "will timeout if execution takes too long" do
64
+ state = nil
65
+
66
+ task = reactor.async do |task|
67
+ task.timeout(0.01) do
68
+ state = :started
69
+ task.sleep(10)
70
+ state = :finished
71
+ end rescue nil
72
+ end
73
+
74
+ reactor.run
75
+
76
+ expect(state).to be == :started
77
+ end
78
+
79
+ it "won't timeout if execution completes in time" do
80
+ state = nil
81
+
82
+ task = reactor.async do |task|
83
+ state = :started
84
+ task.timeout(0.01) do
85
+ task.sleep(0.001)
86
+ state = :finished
87
+ end
88
+ end
89
+
90
+ reactor.run
91
+
92
+ expect(state).to be == :finished
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,41 @@
1
+
2
+ if ENV['COVERAGE'] || ENV['TRAVIS']
3
+ begin
4
+ require 'simplecov'
5
+
6
+ SimpleCov.start do
7
+ add_filter "/spec/"
8
+ end
9
+
10
+ if ENV['TRAVIS']
11
+ require 'coveralls'
12
+ Coveralls.wear!
13
+ end
14
+ rescue LoadError
15
+ warn "Could not load simplecov: #{$!}"
16
+ end
17
+ end
18
+
19
+ require "bundler/setup"
20
+ require "async"
21
+ require "async/tcp_socket"
22
+ require "async/udp_socket"
23
+
24
+ RSpec.shared_context "reactor" do
25
+ let(:reactor) {Async::Reactor.new}
26
+
27
+ around(:each) do |example|
28
+ reactor.run do
29
+ example.run
30
+ end
31
+ end
32
+ end
33
+
34
+ RSpec.configure do |config|
35
+ # Enable flags like --only-failures and --next-failure
36
+ config.example_status_persistence_file_path = ".rspec_status"
37
+
38
+ config.expect_with :rspec do |c|
39
+ c.syntax = :expect
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: async
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nio4r
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: timers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: process-daemon
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.4.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.4.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: "\t\tAsync provides a modern asynchronous I/O framework for Ruby, based\n\t\ton
98
+ nio4r. It implements the reactor pattern, providing both IO and timer\n\t\tbased
99
+ events.\n"
100
+ email:
101
+ - samuel.williams@oriontransfer.co.nz
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Guardfile
111
+ - README.md
112
+ - Rakefile
113
+ - async.gemspec
114
+ - examples/aio.rb
115
+ - lib/async.rb
116
+ - lib/async/io.rb
117
+ - lib/async/logger.rb
118
+ - lib/async/reactor.rb
119
+ - lib/async/socket.rb
120
+ - lib/async/ssl_socket.rb
121
+ - lib/async/task.rb
122
+ - lib/async/tcp_socket.rb
123
+ - lib/async/udp_socket.rb
124
+ - lib/async/unix_socket.rb
125
+ - lib/async/version.rb
126
+ - lib/async/wrapper.rb
127
+ - spec/async/reactor_spec.rb
128
+ - spec/async/task_spec.rb
129
+ - spec/spec_helper.rb
130
+ homepage: https://github.com/socketry/async
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 2.2.6
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.6.10
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Async is an asynchronous I/O framework based on nio4r.
154
+ test_files:
155
+ - spec/async/reactor_spec.rb
156
+ - spec/async/task_spec.rb
157
+ - spec/spec_helper.rb