async-process 1.1.0 → 1.3.1
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 +4 -4
- data/lib/async/process.rb +23 -2
- data/lib/async/process/child.rb +10 -3
- data/lib/async/process/version.rb +1 -1
- metadata +26 -34
- data/.gitignore +0 -12
- data/.rspec +0 -3
- data/.travis.yml +0 -18
- data/Gemfile +0 -5
- data/README.md +0 -77
- data/Rakefile +0 -6
- data/async-process.gemspec +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 952fa23d154d27e2243793967230bd26a76c278b400028f3e26aa88079b3752b
|
4
|
+
data.tar.gz: 58d271855c877f0f8e6db743612fac87c188d1f07c3703e6a5d62c0acd46ac0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed1c7d43f0b63afa9fb16b624daa1c7df102a7aaaf84d9fb636e8dda26205d022c24c18597c10cdafaf4bb4492c564495a6768fe2b13d8d11b4677abce8226ab
|
7
|
+
data.tar.gz: 5fc867164550a1d8b67f4bca13927cedbfa62ba404e9c2cc100883262a5f0cd4bd562e194ed0460e807cc0cab0aff5eff5ba33a31d6c1887a7e76f97e96ff56a
|
data/lib/async/process.rb
CHANGED
@@ -21,10 +21,31 @@
|
|
21
21
|
require 'async/process/version'
|
22
22
|
require 'async/process/child'
|
23
23
|
|
24
|
+
require 'async/io'
|
25
|
+
require 'kernel/sync'
|
26
|
+
|
24
27
|
module Async
|
25
28
|
module Process
|
26
|
-
def self.spawn(*
|
27
|
-
Child.new(*
|
29
|
+
def self.spawn(*arguments, **options)
|
30
|
+
Child.new(*arguments, **options).wait
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.capture(*arguments, **options)
|
34
|
+
input, output = Async::IO.pipe
|
35
|
+
options[:out] = output.io
|
36
|
+
|
37
|
+
runner = Async do
|
38
|
+
spawn(*arguments, **options)
|
39
|
+
ensure
|
40
|
+
output.close
|
41
|
+
end
|
42
|
+
|
43
|
+
Sync do
|
44
|
+
input.read
|
45
|
+
ensure
|
46
|
+
runner.wait
|
47
|
+
input.close
|
48
|
+
end
|
28
49
|
end
|
29
50
|
end
|
30
51
|
end
|
data/lib/async/process/child.rb
CHANGED
@@ -23,14 +23,15 @@ require 'async/io/generic'
|
|
23
23
|
module Async
|
24
24
|
module Process
|
25
25
|
class Child
|
26
|
-
def initialize(*args)
|
26
|
+
def initialize(*args, **options)
|
27
27
|
# Setup a cross-thread notification pipe - nio4r can't monitor pids unfortunately:
|
28
28
|
pipe = ::IO.pipe
|
29
29
|
@input = Async::IO::Generic.new(pipe.first)
|
30
30
|
@output = pipe.last
|
31
31
|
|
32
32
|
@exit_status = nil
|
33
|
-
|
33
|
+
|
34
|
+
@pid = ::Process.spawn(*args, **options, pgroup: true)
|
34
35
|
|
35
36
|
@thread = Thread.new do
|
36
37
|
_, @exit_status = ::Process.wait2(@pid)
|
@@ -38,10 +39,16 @@ module Async
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
42
|
+
attr :pid
|
43
|
+
|
41
44
|
def running?
|
42
45
|
@exit_status.nil?
|
43
46
|
end
|
44
47
|
|
48
|
+
def kill(signal = :TERM)
|
49
|
+
::Process.kill(signal, -@pid)
|
50
|
+
end
|
51
|
+
|
45
52
|
def wait
|
46
53
|
if @exit_status.nil?
|
47
54
|
wait_thread
|
@@ -58,7 +65,7 @@ module Async
|
|
58
65
|
ensure
|
59
66
|
# If the user stops this task, we kill the process:
|
60
67
|
if @exit_status.nil?
|
61
|
-
::Process.kill(:
|
68
|
+
::Process.kill(:KILL, -@pid)
|
62
69
|
end
|
63
70
|
|
64
71
|
@thread.join
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-process
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: async-io
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: async-rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,30 +56,30 @@ dependencies:
|
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: covered
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,27 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.0'
|
97
|
-
description:
|
97
|
+
description:
|
98
98
|
email:
|
99
|
-
- samuel.williams@oriontransfer.co.nz
|
100
99
|
executables: []
|
101
100
|
extensions: []
|
102
101
|
extra_rdoc_files: []
|
103
102
|
files:
|
104
|
-
- ".gitignore"
|
105
|
-
- ".rspec"
|
106
|
-
- ".travis.yml"
|
107
|
-
- Gemfile
|
108
|
-
- README.md
|
109
|
-
- Rakefile
|
110
|
-
- async-process.gemspec
|
111
103
|
- lib/async/process.rb
|
112
104
|
- lib/async/process/child.rb
|
113
105
|
- lib/async/process/version.rb
|
114
106
|
homepage: https://github.com/socketry/async-process
|
115
|
-
licenses:
|
107
|
+
licenses:
|
108
|
+
- MIT
|
116
109
|
metadata: {}
|
117
|
-
post_install_message:
|
110
|
+
post_install_message:
|
118
111
|
rdoc_options: []
|
119
112
|
require_paths:
|
120
113
|
- lib
|
@@ -129,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
122
|
- !ruby/object:Gem::Version
|
130
123
|
version: '0'
|
131
124
|
requirements: []
|
132
|
-
|
133
|
-
|
134
|
-
signing_key:
|
125
|
+
rubygems_version: 3.2.22
|
126
|
+
signing_key:
|
135
127
|
specification_version: 4
|
136
128
|
summary: Asynchronous process spawning.
|
137
129
|
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# Async::Process
|
2
|
-
|
3
|
-
Implements `Process.spawn` for [async].
|
4
|
-
|
5
|
-
[](http://travis-ci.org/socketry/async-process)
|
6
|
-
[](https://codeclimate.com/github/socketry/async-process)
|
7
|
-
[](https://coveralls.io/r/socketry/async-process)
|
8
|
-
|
9
|
-
[async]: https://github.com/socketry/async
|
10
|
-
|
11
|
-
## Installation
|
12
|
-
|
13
|
-
Add this line to your application's Gemfile:
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
gem 'async-process'
|
17
|
-
```
|
18
|
-
|
19
|
-
And then execute:
|
20
|
-
|
21
|
-
$ bundle
|
22
|
-
|
23
|
-
Or install it yourself as:
|
24
|
-
|
25
|
-
$ gem install async-process
|
26
|
-
|
27
|
-
## Usage
|
28
|
-
|
29
|
-
In any asynchronous context (e.g. a reactor), simply use the `Async::Process.spawn` rather than `Process.spawn` like so:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
require 'async/process'
|
33
|
-
|
34
|
-
Async::Reactor.run do
|
35
|
-
status = Async::Process.spawn("ls", "-lah")
|
36
|
-
end
|
37
|
-
```
|
38
|
-
|
39
|
-
Internally, we use a thread, since `nio4r` doesn't support monitoring pids.
|
40
|
-
|
41
|
-
## Contributing
|
42
|
-
|
43
|
-
1. Fork it
|
44
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
-
5. Create new Pull Request
|
48
|
-
|
49
|
-
## See Also
|
50
|
-
|
51
|
-
- [async-io](https://github.com/socketry/async-io) — Asynchronous networking and sockets.
|
52
|
-
- [async-dns](https://github.com/socketry/async-dns) — Asynchronous DNS resolver and server.
|
53
|
-
- [async-rspec](https://github.com/socketry/async-rspec) — Shared contexts for running async specs.
|
54
|
-
|
55
|
-
## License
|
56
|
-
|
57
|
-
Released under the MIT license.
|
58
|
-
|
59
|
-
Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
60
|
-
|
61
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
62
|
-
of this software and associated documentation files (the "Software"), to deal
|
63
|
-
in the Software without restriction, including without limitation the rights
|
64
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
65
|
-
copies of the Software, and to permit persons to whom the Software is
|
66
|
-
furnished to do so, subject to the following conditions:
|
67
|
-
|
68
|
-
The above copyright notice and this permission notice shall be included in
|
69
|
-
all copies or substantial portions of the Software.
|
70
|
-
|
71
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
72
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
73
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
74
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
75
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
76
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
77
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
data/async-process.gemspec
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require_relative "lib/async/process/version"
|
3
|
-
|
4
|
-
Gem::Specification.new do |spec|
|
5
|
-
spec.name = "async-process"
|
6
|
-
spec.version = Async::Process::VERSION
|
7
|
-
spec.authors = ["Samuel Williams"]
|
8
|
-
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
9
|
-
|
10
|
-
spec.summary = "Asynchronous process spawning."
|
11
|
-
spec.homepage = "https://github.com/socketry/async-process"
|
12
|
-
|
13
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
14
|
-
f.match(%r{^(test|spec|features)/})
|
15
|
-
end
|
16
|
-
|
17
|
-
spec.require_paths = ["lib"]
|
18
|
-
|
19
|
-
spec.add_dependency "async", "~> 1.0"
|
20
|
-
spec.add_dependency "async-io", "~> 1.0"
|
21
|
-
spec.add_development_dependency "async-rspec", "~> 1.1"
|
22
|
-
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.15"
|
24
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
-
end
|