pax_global_header00006660000000000000000000000064147133133410014512gustar00rootroot0000000000000052 comment=3a9ad30ba1552af8d2de5f477be351943a184ec6 socketry-async-process-3a9ad30/000077500000000000000000000000001471331334100165525ustar00rootroot00000000000000socketry-async-process-3a9ad30/.editorconfig000066400000000000000000000001511471331334100212240ustar00rootroot00000000000000root = true [*] indent_style = tab indent_size = 2 [*.{yml,yaml}] indent_style = space indent_size = 2 socketry-async-process-3a9ad30/.github/000077500000000000000000000000001471331334100201125ustar00rootroot00000000000000socketry-async-process-3a9ad30/.github/workflows/000077500000000000000000000000001471331334100221475ustar00rootroot00000000000000socketry-async-process-3a9ad30/.github/workflows/documentation-coverage.yaml000066400000000000000000000007021471331334100274740ustar00rootroot00000000000000name: Documentation Coverage on: [push, pull_request] permissions: contents: read env: CONSOLE_OUTPUT: XTerm COVERAGE: PartialSummary jobs: validate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: "3.3" bundler-cache: true - name: Validate coverage timeout-minutes: 5 run: bundle exec bake decode:index:coverage lib socketry-async-process-3a9ad30/.github/workflows/documentation.yaml000066400000000000000000000021621471331334100257050ustar00rootroot00000000000000name: Documentation on: push: branches: - main # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages: permissions: contents: read pages: write id-token: write # Allow one concurrent deployment: concurrency: group: "pages" cancel-in-progress: true env: CONSOLE_OUTPUT: XTerm BUNDLE_WITH: maintenance jobs: generate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: "3.3" bundler-cache: true - name: Installing packages run: sudo apt-get install wget - name: Generate documentation timeout-minutes: 5 run: bundle exec bake utopia:project:static --force no - name: Upload documentation artifact uses: actions/upload-pages-artifact@v3 with: path: docs deploy: runs-on: ubuntu-latest environment: name: github-pages url: ${{steps.deployment.outputs.page_url}} needs: generate steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 socketry-async-process-3a9ad30/.github/workflows/rubocop.yaml000066400000000000000000000005701471331334100245060ustar00rootroot00000000000000name: RuboCop on: [push, pull_request] permissions: contents: read env: CONSOLE_OUTPUT: XTerm jobs: check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ruby bundler-cache: true - name: Run RuboCop timeout-minutes: 10 run: bundle exec rubocop socketry-async-process-3a9ad30/.github/workflows/test-coverage.yaml000066400000000000000000000022351471331334100256050ustar00rootroot00000000000000name: Test Coverage on: [push, pull_request] permissions: contents: read env: CONSOLE_OUTPUT: XTerm COVERAGE: PartialSummary jobs: test: name: ${{matrix.ruby}} on ${{matrix.os}} runs-on: ${{matrix.os}}-latest strategy: matrix: os: - ubuntu - macos ruby: - "3.3" steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{matrix.ruby}} bundler-cache: true - name: Run tests timeout-minutes: 5 run: bundle exec bake test - uses: actions/upload-artifact@v4 with: include-hidden-files: true if-no-files-found: error name: coverage-${{matrix.os}}-${{matrix.ruby}} path: .covered.db validate: needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: "3.3" bundler-cache: true - uses: actions/download-artifact@v4 - name: Validate coverage timeout-minutes: 5 run: bundle exec bake covered:validate --paths */.covered.db \; socketry-async-process-3a9ad30/.github/workflows/test-external.yaml000066400000000000000000000011461471331334100256340ustar00rootroot00000000000000name: Test External on: [push, pull_request] permissions: contents: read env: CONSOLE_OUTPUT: XTerm jobs: test: name: ${{matrix.ruby}} on ${{matrix.os}} runs-on: ${{matrix.os}}-latest strategy: matrix: os: - ubuntu - macos ruby: - "3.1" - "3.2" - "3.3" steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{matrix.ruby}} bundler-cache: true - name: Run tests timeout-minutes: 10 run: bundle exec bake test:external socketry-async-process-3a9ad30/.github/workflows/test.yaml000066400000000000000000000016641471331334100240210ustar00rootroot00000000000000name: Test on: [push, pull_request] permissions: contents: read env: CONSOLE_OUTPUT: XTerm jobs: test: name: ${{matrix.ruby}} on ${{matrix.os}} runs-on: ${{matrix.os}}-latest continue-on-error: ${{matrix.experimental}} strategy: matrix: os: - ubuntu - macos ruby: - "3.1" - "3.2" - "3.3" experimental: [false] include: - os: ubuntu ruby: truffleruby experimental: true - os: ubuntu ruby: jruby experimental: true - os: ubuntu ruby: head experimental: true steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{matrix.ruby}} bundler-cache: true - name: Run tests timeout-minutes: 10 run: bundle exec bake test socketry-async-process-3a9ad30/.gitignore000066400000000000000000000000641471331334100205420ustar00rootroot00000000000000/.bundle/ /pkg/ /gems.locked /.covered.db /external socketry-async-process-3a9ad30/.rubocop.yml000066400000000000000000000015321471331334100210250ustar00rootroot00000000000000AllCops: DisabledByDefault: true Layout/IndentationStyle: Enabled: true EnforcedStyle: tabs Layout/InitialIndentation: Enabled: true Layout/IndentationWidth: Enabled: true Width: 1 Layout/IndentationConsistency: Enabled: true EnforcedStyle: normal Layout/BlockAlignment: Enabled: true Layout/EndAlignment: Enabled: true EnforcedStyleAlignWith: start_of_line Layout/BeginEndAlignment: Enabled: true EnforcedStyleAlignWith: start_of_line Layout/ElseAlignment: Enabled: true Layout/DefEndAlignment: Enabled: true Layout/CaseIndentation: Enabled: true Layout/CommentIndentation: Enabled: true Layout/EmptyLinesAroundClassBody: Enabled: true Layout/EmptyLinesAroundModuleBody: Enabled: true Style/FrozenStringLiteralComment: Enabled: true Style/StringLiterals: Enabled: true EnforcedStyle: double_quotes socketry-async-process-3a9ad30/async-process.gemspec000066400000000000000000000013331471331334100227100ustar00rootroot00000000000000# frozen_string_literal: true require_relative "lib/async/process/version" Gem::Specification.new do |spec| spec.name = "async-process" spec.version = Async::Process::VERSION spec.summary = "Asynchronous process spawning." spec.authors = ["Samuel Williams", "Joe Khoobyar"] spec.license = "MIT" spec.cert_chain = ["release.cert"] spec.signing_key = File.expand_path("~/.gem/release.pem") spec.homepage = "https://github.com/socketry/async-process" spec.metadata = { "source_code_uri" => "https://github.com/socketry/async-process.git", } spec.files = Dir.glob(["{lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__) spec.required_ruby_version = ">= 3.1" spec.add_dependency "async", "~> 2.0" end socketry-async-process-3a9ad30/config/000077500000000000000000000000001471331334100200175ustar00rootroot00000000000000socketry-async-process-3a9ad30/config/sus.rb000066400000000000000000000002241471331334100211540ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2024, by Samuel Williams. require "covered/sus" include Covered::Sus socketry-async-process-3a9ad30/gems.rb000066400000000000000000000006221471331334100200320ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2021-2024, by Samuel Williams. source "https://rubygems.org" gemspec group :maintenance, optional: true do gem "bake-modernize" gem "bake-gem" gem "utopia-project" end group :test do gem "sus" gem "covered" gem "decode" gem "rubocop" gem "sus-fixtures-async" gem "bake-test" gem "bake-test-external" end socketry-async-process-3a9ad30/lib/000077500000000000000000000000001471331334100173205ustar00rootroot00000000000000socketry-async-process-3a9ad30/lib/async/000077500000000000000000000000001471331334100204355ustar00rootroot00000000000000socketry-async-process-3a9ad30/lib/async/process.rb000066400000000000000000000011721471331334100224410ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2024, by Samuel Williams. # Copyright, 2020, by Joe Khoobyar. require "async/process/version" require "async/process/child" require "kernel/sync" module Async module Process def self.spawn(*arguments, **options) Child.new(*arguments, **options).wait end def self.capture(*arguments, **options) input, output = ::IO.pipe options[:out] = output runner = Async do spawn(*arguments, **options) ensure output.close end Sync do input.read ensure runner.wait input.close end end end end socketry-async-process-3a9ad30/lib/async/process/000077500000000000000000000000001471331334100221135ustar00rootroot00000000000000socketry-async-process-3a9ad30/lib/async/process/child.rb000066400000000000000000000021331471331334100235220ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2024, by Samuel Williams. module Async module Process class Child def initialize(*args, **options) # Setup a cross-thread notification pipe - nio4r can't monitor pids unfortunately: pipe = ::IO.pipe @input = pipe.first @output = pipe.last @exit_status = nil @pid = ::Process.spawn(*args, **options, pgroup: true) @thread = Thread.new do _, @exit_status = ::Process.wait2(@pid) @output.close end end attr :pid def running? @exit_status.nil? end def kill(signal = :TERM) ::Process.kill(signal, -@pid) end def wait if @exit_status.nil? wait_thread end return @exit_status end private def wait_thread @input.read(1) ensure # If the user stops this task, we kill the process: if @exit_status.nil? ::Process.kill(:KILL, -@pid) end @thread.join # We are done with the notification pipe: @input.close @output.close end end end end socketry-async-process-3a9ad30/lib/async/process/version.rb000066400000000000000000000002501471331334100241220ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2024, by Samuel Williams. module Async module Process VERSION = "1.4.0" end end socketry-async-process-3a9ad30/license.md000066400000000000000000000021371471331334100205210ustar00rootroot00000000000000# MIT License Copyright, 2018-2024, by Samuel Williams. Copyright, 2020, by Joe Khoobyar. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. socketry-async-process-3a9ad30/readme.md000066400000000000000000000035111471331334100203310ustar00rootroot00000000000000# Async::Process Implements `Process.spawn` and `Process.capture` for [async](https://github.com/socketry/async). [![Development Status](https://github.com/socketry/async-process/workflows/Test/badge.svg)](https://github.com/socketry/async-process/actions?workflow=Test) ## Installation Add this line to your application's Gemfile: ``` ruby gem 'async-process' ``` And then execute: $ bundle Or install it yourself as: $ gem install async-process ## Usage In any asynchronous context (e.g. a reactor), simply use the `Async::Process.spawn` rather than `Process.spawn` like so: ``` ruby require 'async/process' Async::Reactor.run do status = Async::Process.spawn("ls", "-lah") end ``` Internally, we use a thread, since `nio4r` doesn't support monitoring pids. ## Contributing We welcome contributions to this project. 1. Fork it. 2. Create your feature branch (`git checkout -b my-new-feature`). 3. Commit your changes (`git commit -am 'Add some feature'`). 4. Push to the branch (`git push origin my-new-feature`). 5. Create new Pull Request. ### Developer Certificate of Origin In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed. ### Community Guidelines This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers. ## See Also - [async-container](https://github.com/socketry/async-container) — Execute multiple isolated threads and/or processes. socketry-async-process-3a9ad30/release.cert000066400000000000000000000033141471331334100210520ustar00rootroot00000000000000-----BEGIN CERTIFICATE----- MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11 ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd MBsGCgmSJomT8ixkARkWDW9yaW9udHJh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IfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8 voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg= -----END CERTIFICATE----- socketry-async-process-3a9ad30/test/000077500000000000000000000000001471331334100175315ustar00rootroot00000000000000socketry-async-process-3a9ad30/test/async/000077500000000000000000000000001471331334100206465ustar00rootroot00000000000000socketry-async-process-3a9ad30/test/async/process.rb000066400000000000000000000007451471331334100226570ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2024, by Samuel Williams. require "async/process" require "sus/fixtures/async" describe Async::Process do include Sus::Fixtures::Async::ReactorContext it "should execute sub-process" do status = subject.spawn("ls", "-lah") expect(status).to be(:success?) end it "can capture output" do output = subject.capture("ls", "-lah") expect(output).to be(:include?, "async-process") end end socketry-async-process-3a9ad30/test/async/process/000077500000000000000000000000001471331334100223245ustar00rootroot00000000000000socketry-async-process-3a9ad30/test/async/process/child.rb000066400000000000000000000014701471331334100237360ustar00rootroot00000000000000# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2024, by Samuel Williams. require "async/process" require "sus/fixtures/async" describe Async::Process::Child do include Sus::Fixtures::Async::ReactorContext it "will terminate sub-process when stopping task" do child = nil task = reactor.async do child = subject.new("sleep 60") child.wait end expect(child).to be(:running?) task.stop task.wait expect(child).not.to be(:running?) end with "#kill" do it "can kill child process" do child = subject.new("sleep 60") expect(child).to be(:running?) child.kill status = child.wait expect(child).not.to be(:running?) expect(status).to be_a(Process::Status) expect(status).not.to be(:success?) end end end