async 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/async/task.rb +6 -7
- data/lib/async/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a53fcaec5de211edad59be553e0a79428a6033f6
|
4
|
+
data.tar.gz: a3f0c6e234ba5b7e0d31d83e3c4e2d866a9118ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d3e0bbe7877ef2db58d51d078cfe1c66c93fffa1bcc41d3208766b3b28c48488274e5a3df7d393d982e214a08cfd1d7cf749ad4f939caf217c50c5418782ff8
|
7
|
+
data.tar.gz: f3781101e3f0fd51de46d2a4fa9e97369ac88afb4eb0c115d7aaa48f10f7e032309067e0267f55210c07f3ff28d4cd71e368ac556bf886882012ecdfd7bb87fe
|
data/README.md
CHANGED
@@ -81,7 +81,7 @@ This method effectively creates a child task. It's the most efficient way to sch
|
|
81
81
|
|
82
82
|
`Async::Reactor` and `Async::Task` form nodes in a tree. Reactors and tasks can spawn children tasks. When you invoke `Async::Reactor#async`, the parent task is determined by calling `Async::Task.current?` which uses fiber local storage. A slightly more efficient method is to use `Async::Task#async`, which uses `self` as the parent task.
|
83
83
|
|
84
|
-
When invoking `Async::Reactor#stop`, you will stop *all* children tasks of that reactor. Tasks will raise `Async::
|
84
|
+
When invoking `Async::Reactor#stop`, you will stop *all* children tasks of that reactor. Tasks will raise `Async::Stop` if they are in a blocking operation. In addition, it's possible to only stop a sub-tree by issuing `Async::Task#stop`, which will stop that task and all it's children (recursively). When you design a server, you should return the task back to the caller. They can use this task to stop the server if needed, independently of any other unrelated tasks within the reactor, and it will correctly clean up all related tasks.
|
85
85
|
|
86
86
|
### Resource Management
|
87
87
|
|
@@ -90,10 +90,10 @@ In order to ensure your resources are cleaned up correctly, make sure you wrap r
|
|
90
90
|
```ruby
|
91
91
|
Async::Reactor.run do
|
92
92
|
begin
|
93
|
-
socket = connect(remote_address) # May raise Async::
|
93
|
+
socket = connect(remote_address) # May raise Async::Stop so socket could be nil
|
94
94
|
|
95
|
-
socket.write(...) # May raise Async::
|
96
|
-
socket.read(...) # May raise Async::
|
95
|
+
socket.write(...) # May raise Async::Stop
|
96
|
+
socket.read(...) # May raise Async::Stop
|
97
97
|
ensure
|
98
98
|
socket.close if socket
|
99
99
|
end
|
data/lib/async/task.rb
CHANGED
@@ -26,7 +26,7 @@ require_relative 'condition'
|
|
26
26
|
|
27
27
|
module Async
|
28
28
|
# Raised when a task is explicitly stopped.
|
29
|
-
class
|
29
|
+
class Stop < Exception
|
30
30
|
end
|
31
31
|
|
32
32
|
# A task represents the state associated with the execution of an asynchronous
|
@@ -74,9 +74,9 @@ module Async
|
|
74
74
|
@result = yield(self, *args)
|
75
75
|
@status = :complete
|
76
76
|
# Async.logger.debug("Task #{self} completed normally.")
|
77
|
-
rescue
|
78
|
-
@status = :
|
79
|
-
# Async.logger.debug("Task #{self}
|
77
|
+
rescue Stop
|
78
|
+
@status = :stop
|
79
|
+
# Async.logger.debug("Task #{self} stopped: #{$!}")
|
80
80
|
rescue Exception => error
|
81
81
|
@result = error
|
82
82
|
@status = :failed
|
@@ -101,7 +101,7 @@ module Async
|
|
101
101
|
attr :fiber
|
102
102
|
def_delegators :@fiber, :alive?
|
103
103
|
|
104
|
-
# @attr status [Symbol] The status of the execution of the fiber, one of `:running`, `:complete`, `:
|
104
|
+
# @attr status [Symbol] The status of the execution of the fiber, one of `:running`, `:complete`, `:stopped`, or `:failed`.
|
105
105
|
attr :status
|
106
106
|
|
107
107
|
# Resume the execution of the task.
|
@@ -144,8 +144,7 @@ module Async
|
|
144
144
|
@children.each(&:stop)
|
145
145
|
|
146
146
|
if @fiber.alive?
|
147
|
-
|
148
|
-
@fiber.resume(exception)
|
147
|
+
@fiber.resume(Stop.new)
|
149
148
|
end
|
150
149
|
end
|
151
150
|
|
data/lib/async/version.rb
CHANGED
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: 0.
|
4
|
+
version: 0.17.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: 2017-06-
|
11
|
+
date: 2017-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|