async 1.5.0 → 1.6.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: fbcd86e787f3949c50b5cc5f2aa05dd538bfc51bd6b56ee13f9a401e8becf567
4
- data.tar.gz: e6e35d12fa6c08dd70e31de4ad8689506f80a6daa90a35af98cda331bf06e139
3
+ metadata.gz: 9cd2107a53d168c8c2d2cd1361d66d8f05df65ba0736b131ce718a17c3607bac
4
+ data.tar.gz: 22872f2281ebc86ab5652cd53ca050d2470723d10820de8f90c2cde7a0513557
5
5
  SHA512:
6
- metadata.gz: 668b4300208b250bd012ee41d3aa4612f22e3d7b6b22904396be2b52ea7eaef8ef5273b5996eaeebbfcfb3d072def93137614d58f1ef5a112ef75f17067c598b
7
- data.tar.gz: 48dc3517c920260e26f3e1f2bd0835d857d32c5c253e634562a70f6f145a12d338e3e4f48adff206c0d23b0f4dde096522908970a49c29d07682aa95d2df3ec4
6
+ metadata.gz: cc961f8e16a6e5713c6bfe64593ad4877fc5522476e813481b51a5f9dfec272b163d7828ddb6360c37c0696be021535a61e371816338c83fdb85d9eb4dfa07c7
7
+ data.tar.gz: 61362063d6dfe7162bb1f9f1c7d396513b6042a8e64acac831928b0c0849a6564ab4aeccb4c4b0cb47801255e143876a5ef4f7f8cb5b8fb3a870c06e1a70311c
@@ -0,0 +1,37 @@
1
+ # Copyright, 2018, 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 Clock
23
+ # Get the current elapsed monotonic time.
24
+ def self.now
25
+ ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
26
+ end
27
+
28
+ # Measure the execution of a block of code.
29
+ def self.measure
30
+ start_time = self.now
31
+
32
+ yield
33
+
34
+ return self.now - start_time
35
+ end
36
+ end
37
+ end
@@ -29,6 +29,8 @@ module Async
29
29
  @items = []
30
30
  end
31
31
 
32
+ attr :items
33
+
32
34
  def enqueue item
33
35
  @items.push(item)
34
36
 
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Async
22
- VERSION = "1.5.0"
22
+ VERSION = "1.6.0"
23
23
  end
@@ -0,0 +1,35 @@
1
+ # Copyright, 2018, 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 'async/clock'
22
+
23
+ RSpec.describe Async::Clock do
24
+ it "can measure durations" do
25
+ duration = Async::Clock.measure do
26
+ sleep 0.1
27
+ end
28
+
29
+ expect(duration).to be_within(0.01).of(0.1)
30
+ end
31
+
32
+ it "can get current offset" do
33
+ expect(Async::Clock.now).to be_kind_of Float
34
+ end
35
+ end
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.5.0
4
+ version: 1.6.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-04-08 00:00:00.000000000 Z
11
+ date: 2018-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r
@@ -118,6 +118,7 @@ files:
118
118
  - examples/fibers.rb
119
119
  - examples/sleep_sort.rb
120
120
  - lib/async.rb
121
+ - lib/async/clock.rb
121
122
  - lib/async/condition.rb
122
123
  - lib/async/logger.rb
123
124
  - lib/async/measure.rb
@@ -132,6 +133,7 @@ files:
132
133
  - logo.svg
133
134
  - papers/1982 Grossman.pdf
134
135
  - papers/1987 ODell.pdf
136
+ - spec/async/clock_spec.rb
135
137
  - spec/async/condition_examples.rb
136
138
  - spec/async/condition_spec.rb
137
139
  - spec/async/logger_spec.rb
@@ -169,6 +171,7 @@ signing_key:
169
171
  specification_version: 4
170
172
  summary: Async is an asynchronous I/O framework based on nio4r.
171
173
  test_files:
174
+ - spec/async/clock_spec.rb
172
175
  - spec/async/condition_examples.rb
173
176
  - spec/async/condition_spec.rb
174
177
  - spec/async/logger_spec.rb