async-await 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c115c979974936f460f8c73b51c209005bc175fbb3f1d252d46f3257515cbb0a
4
- data.tar.gz: 00e46441e57ff43924bc62c3563739bdf036f4f2999aabfe80d54862d5c096e4
3
+ metadata.gz: a6bd51107b67f26bed6fd124f44569ebc65722f1511155e0ea47d7771fb3ef26
4
+ data.tar.gz: dfd1c275e5cdc7d2f8cc6d072fb1ff4435fc80b73cf8f149f91c198225897b24
5
5
  SHA512:
6
- metadata.gz: b579efc91d103e3819a3928dc370c11403bee51460c0089774e1374f1587a8913a80d745829ebe57cd7f0eaa349732453ab8e7ad06329f2053bfc3c0711dc53b
7
- data.tar.gz: d72e8143f192204a6b061ae05f6bc4bb0753e621b69e765e55ecfdc8d21da7a1b0306c88eb5d71841debb6628fdd24f324009176c54922e945b6b0271e5767e4
6
+ metadata.gz: 59cc0fa94b7bd1d9dad30dc5c0ce6753964e5582bd3d73b37288c69bc6f510993c786fdb999872d9f823eab5e1ae5b6ef21087ec4e94fe9da251f8c377b7eb3d
7
+ data.tar.gz: f36524a212b64167b92e4133e6d82f78d375c5954a2601476ce3eae30f9efeea781a3b7d2d412a83bd8545f8011e9c423ad220f8d4a5f63a1e4f4b904e3dea86
@@ -37,7 +37,7 @@ class PortScanner
37
37
  end
38
38
 
39
39
  limits = Process.getrlimit(Process::RLIMIT_NOFILE)
40
- batch_size = [512, limits.first].min
40
+ batch_size = [512, (limits.first * 0.9).ceil].min
41
41
 
42
42
  scanner = PortScanner.new(host: "127.0.0.1", ports: Range.new(1, 65535), batch_size: batch_size)
43
43
 
@@ -28,6 +28,22 @@ module Async
28
28
  klass.extend(self)
29
29
  end
30
30
 
31
+ def sync(name)
32
+ original_method = instance_method(name)
33
+
34
+ remove_method(name)
35
+
36
+ define_method(name) do |*args|
37
+ if task = Task.current?
38
+ original_method.bind(self).call(*args)
39
+ else
40
+ Async::Reactor.run do
41
+ original_method.bind(self).call(*args)
42
+ end.wait
43
+ end
44
+ end
45
+ end
46
+
31
47
  def async(name)
32
48
  original_method = instance_method(name)
33
49
 
@@ -0,0 +1,51 @@
1
+ # Copyright, 2019, 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
+ module Async
22
+ module Await
23
+ module Enumerable
24
+ def async_map(parent: Task.current, &block)
25
+ self.map do |*args|
26
+ parent.async do
27
+ yield *args
28
+ end
29
+ end.map(&:wait)
30
+ end
31
+
32
+ def async_each(parent: Task.current, &block)
33
+ self.each do |*args|
34
+ parent.async do
35
+ yield *args
36
+ end
37
+ end
38
+
39
+ return self
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ # ::Enumerable.include(Async::Await::Enumerable)
46
+ # https://bugs.ruby-lang.org/issues/9573
47
+ module Enumerable
48
+ Async::Await::Enumerable.instance_methods.each do |name|
49
+ self.define_method(name, Async::Await::Enumerable.instance_method(name))
50
+ end
51
+ end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module Await
23
- VERSION = "0.3.0"
23
+ VERSION = "0.4.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-await
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.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: 2019-02-11 00:00:00.000000000 Z
11
+ date: 2020-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -117,6 +117,7 @@ files:
117
117
  - examples/port_scanner/port_scanner.rb
118
118
  - examples/sleep_sort.rb
119
119
  - lib/async/await.rb
120
+ - lib/async/await/enumerable.rb
120
121
  - lib/async/await/methods.rb
121
122
  - lib/async/await/version.rb
122
123
  homepage: https://github.com/socketry/async-await
@@ -137,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
138
  - !ruby/object:Gem::Version
138
139
  version: '0'
139
140
  requirements: []
140
- rubygems_version: 3.0.2
141
+ rubygems_version: 3.1.2
141
142
  signing_key:
142
143
  specification_version: 4
143
144
  summary: Implements the async/await pattern on top of async :)