async 1.10.3 → 1.11.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c6969a926be43959827ea7fae56a4a8c099bb25fe5311fca54ed1ca4f30407b
4
- data.tar.gz: 03afef10466d6ce5868e7fbe6357d4e356650ee347be1db47c23e603d34fa29d
3
+ metadata.gz: f78e59e65f039a595f3090930e0492e824193a02ffd47c77cd640b22ca02706b
4
+ data.tar.gz: 2212445905b0c5b3603bec13a64e6e8254d30b9c232f4749b96171b6c13f5279
5
5
  SHA512:
6
- metadata.gz: 0ea28be7e1534cb72dc4fd81b7c12e5548c363837c4620aa13a256977bbefbbe7554a09b93eadea10c092db5fb808bd5a1392ee54bb8f27a5b5e92fd2ba51b85
7
- data.tar.gz: d69372c3b1e194f0cbcdb3e8a5eca55843dd9a5fcca956ef7ea0094776b566ff789a59c9ad0ac1b4d3d1d8f851bcf8846e11ad4731f887cfaffd8841a71c0689
6
+ metadata.gz: 422d14fb58bb6290c2d3761df6fed9cdf647b316c0368b97d6ce0993309f366172bf332dd039dd95c4c384d0c5f77e62a7b4003e18ba8291ac20ecd79c1a14c4
7
+ data.tar.gz: 4d748c040e6f630191a3eb64ddf0bb9374c70857e42f1ddcc122c3fd172f7ce2d6104555731237aafdc669691620f3a2c90fae3b2dee05fa7aefc1feea0842bd
@@ -2,4 +2,5 @@ root = true
2
2
 
3
3
  [*]
4
4
  indent_style = tab
5
- indent_size = 4
5
+ indent_size = 2
6
+
data/README.md CHANGED
@@ -123,11 +123,15 @@ Due to limitations within Ruby and the nature of this library, it is not possibl
123
123
 
124
124
  - [async-io](https://github.com/socketry/async-io) — Asynchronous networking and sockets.
125
125
  - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client/server.
126
- - [falcon](https://github.com/socketry/falcon) — A rack compatible server built on top of `async-http`.
127
126
  - [async-process](https://github.com/socketry/async-process) — Asynchronous process spawning/waiting.
128
127
  - [async-websocket](https://github.com/socketry/async-websocket) — Asynchronous client and server websockets.
129
128
  - [async-dns](https://github.com/socketry/async-dns) — Asynchronous DNS resolver and server.
130
129
  - [async-rspec](https://github.com/socketry/async-rspec) — Shared contexts for running async specs.
130
+
131
+ ### Projects Using Async
132
+
133
+ - [ciri](https://github.com/ciri-ethereum/ciri) - An Ethereum implementation written in Ruby.
134
+ - [falcon](https://github.com/socketry/falcon) — A rack compatible server built on top of `async-http`.
131
135
  - [rubydns](https://github.com/ioquatix/rubydns) — A easy to use Ruby DNS server.
132
136
 
133
137
  ## License
@@ -19,8 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ["lib"]
22
- spec.has_rdoc = "yard"
23
-
22
+
24
23
  spec.required_ruby_version = ">= 2.2.7"
25
24
 
26
25
  spec.add_runtime_dependency "nio4r", "~> 2.3"
@@ -0,0 +1,43 @@
1
+
2
+ require 'async/reactor'
3
+
4
+ class Callback
5
+ def initialize
6
+ @reactor = Async::Reactor.new
7
+ end
8
+
9
+ def close
10
+ @reactor.close
11
+ end
12
+
13
+ # If duration is 0, it will happen immediately after the task is started.
14
+ def run(duration = 0)
15
+ @reactor.run do |task|
16
+ @reactor.after(duration) do
17
+ @reactor.stop
18
+ end
19
+
20
+ yield(task) if block_given?
21
+ end
22
+ end
23
+ end
24
+
25
+
26
+ callback = Callback.new
27
+
28
+ begin
29
+ callback.run do |task|
30
+ while true
31
+ task.sleep(2)
32
+ puts "Hello from task!"
33
+ end
34
+ end
35
+
36
+ while true
37
+ callback.run(0)
38
+ puts "Sleeping for 1 second"
39
+ sleep(1)
40
+ end
41
+ ensure
42
+ callback.close
43
+ end
@@ -235,13 +235,13 @@ module Async
235
235
  # currenly blocking operation.
236
236
  # @param duration [Integer] The time in seconds, in which the task should
237
237
  # complete.
238
- def timeout(duration)
238
+ def timeout(duration, exception = TimeoutError)
239
239
  backtrace = caller
240
240
  fiber = Fiber.current
241
241
 
242
242
  timer = self.after(duration) do
243
243
  if fiber.alive?
244
- error = TimeoutError.new("execution expired")
244
+ error = exception.new("execution expired")
245
245
  error.set_backtrace backtrace
246
246
  fiber.resume error
247
247
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Async
22
- VERSION = "1.10.3"
22
+ VERSION = "1.11.0"
23
23
  end
@@ -144,6 +144,18 @@ RSpec.describe Async::Reactor do
144
144
 
145
145
  expect(duration).to be < 0.1
146
146
  end
147
+
148
+ let(:timeout_class) {Class.new(RuntimeError)}
149
+
150
+ it "raises specified exception" do
151
+ expect do
152
+ described_class.run do |task|
153
+ task.timeout(0.0, timeout_class) do
154
+ task.sleep(1.0)
155
+ end
156
+ end
157
+ end.to raise_error(timeout_class)
158
+ end
147
159
  end
148
160
 
149
161
  describe '#to_s' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.3
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-21 00:00:00.000000000 Z
11
+ date: 2018-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r
@@ -115,6 +115,7 @@ files:
115
115
  - async.gemspec
116
116
  - benchmark/async_vs_lightio.rb
117
117
  - examples/async_method.rb
118
+ - examples/callback/loop.rb
118
119
  - examples/fibers.rb
119
120
  - examples/sleep_sort.rb
120
121
  - lib/async.rb
@@ -171,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  version: '0'
172
173
  requirements: []
173
174
  rubyforge_project:
174
- rubygems_version: 2.7.6
175
+ rubygems_version: 2.7.7
175
176
  signing_key:
176
177
  specification_version: 4
177
178
  summary: Async is an asynchronous I/O framework based on nio4r.