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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 666f1e442c6185c4e77ae21c8c0033ce9ba30d04649f3b893d7e823c2aa157ae
4
- data.tar.gz: 6d4568ed5ff3da456748b480bf1ed559b91518012ef62c049f3de120dc2b755e
3
+ metadata.gz: 952fa23d154d27e2243793967230bd26a76c278b400028f3e26aa88079b3752b
4
+ data.tar.gz: 58d271855c877f0f8e6db743612fac87c188d1f07c3703e6a5d62c0acd46ac0e
5
5
  SHA512:
6
- metadata.gz: cd99f72e74854e158a48e01a4de54452de521049c9b070eb1df293b5c58a6da11b92a40023944da91f660310b70b3f364d5bdeb3c46e402d51c6c320259de0b5
7
- data.tar.gz: 18de8e7d84d7b5804af4fa3fc24730a8620f37bf02da1380570ffe7b743975e0c0a26df21447c323539d1990da9702a1dd72aa69656e6384392cbda87f2aeb61
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(*args)
27
- Child.new(*args).wait
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
@@ -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
- @pid = ::Process.spawn(*args)
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(:TERM, @pid)
68
+ ::Process.kill(:KILL, -@pid)
62
69
  end
63
70
 
64
71
  @thread.join
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module Process
23
- VERSION = "1.1.0"
23
+ VERSION = "1.3.1"
24
24
  end
25
25
  end
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.0
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: 2018-08-19 00:00:00.000000000 Z
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: '1.0'
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: '1.0'
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: '1.0'
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: '1.0'
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: '1.15'
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: '1.15'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: covered
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
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: '10.0'
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
- rubyforge_project:
133
- rubygems_version: 2.7.7
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
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --warnings
3
- --require spec_helper
data/.travis.yml DELETED
@@ -1,18 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- dist: trusty
4
- cache: bundler
5
- rvm:
6
- - 2.0
7
- - 2.1
8
- - 2.2
9
- - 2.3
10
- - 2.4
11
- - jruby-head
12
- - ruby-head
13
- - rbx-3
14
- matrix:
15
- allow_failures:
16
- - rvm: ruby-head
17
- - rvm: jruby-head
18
- - rvm: rbx-3
data/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- gemspec
data/README.md DELETED
@@ -1,77 +0,0 @@
1
- # Async::Process
2
-
3
- Implements `Process.spawn` for [async].
4
-
5
- [![Build Status](https://secure.travis-ci.org/socketry/async-process.svg)](http://travis-ci.org/socketry/async-process)
6
- [![Code Climate](https://codeclimate.com/github/socketry/async-process.svg)](https://codeclimate.com/github/socketry/async-process)
7
- [![Coverage Status](https://coveralls.io/repos/socketry/async-process/badge.svg)](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
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -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