async 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/clock.rb +37 -0
- data/lib/async/queue.rb +2 -0
- data/lib/async/version.rb +1 -1
- data/spec/async/clock_spec.rb +35 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cd2107a53d168c8c2d2cd1361d66d8f05df65ba0736b131ce718a17c3607bac
|
4
|
+
data.tar.gz: 22872f2281ebc86ab5652cd53ca050d2470723d10820de8f90c2cde7a0513557
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc961f8e16a6e5713c6bfe64593ad4877fc5522476e813481b51a5f9dfec272b163d7828ddb6360c37c0696be021535a61e371816338c83fdb85d9eb4dfa07c7
|
7
|
+
data.tar.gz: 61362063d6dfe7162bb1f9f1c7d396513b6042a8e64acac831928b0c0849a6564ab4aeccb4c4b0cb47801255e143876a5ef4f7f8cb5b8fb3a870c06e1a70311c
|
data/lib/async/clock.rb
ADDED
@@ -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
|
data/lib/async/queue.rb
CHANGED
data/lib/async/version.rb
CHANGED
@@ -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.
|
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-
|
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
|