Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Move em-posix-spawn to Warden
Browse files Browse the repository at this point in the history
Relocate and update dependencies

Signed-off-by: Sandy Cash <[email protected]>
  • Loading branch information
Michael Fraenkel authored and Anonymous Coward committed Jan 8, 2016
1 parent 09c37bf commit 3916db2
Show file tree
Hide file tree
Showing 10 changed files with 1,188 additions and 0 deletions.
2 changes: 2 additions & 0 deletions em-posix-spawn/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source "http://rubygems.org"
gemspec
25 changes: 25 additions & 0 deletions em-posix-spawn/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
PATH
remote: .
specs:
em-posix-spawn (0.1.10)
eventmachine
posix-spawn

GEM
remote: http://rubygems.org/
specs:
eventmachine (1.0.8)
minitest (5.8.3)
posix-spawn (0.3.11)
rake (10.4.2)

PLATFORMS
ruby

DEPENDENCIES
em-posix-spawn!
minitest
rake

BUNDLED WITH
1.11.2
57 changes: 57 additions & 0 deletions em-posix-spawn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# `em-posix-spawn`

This module provides an interface to `POSIX::Spawn` for EventMachine. In
particular, it contains an EventMachine equivalent to `POSIX::Spawn::Child`.
This class encapsulates writing to the child process its stdin and reading from
both its stdout and stderr. Only when the process has exited, it triggers a
callback to notify others of its completion. Just as `POSIX::Spawn::Child`,
this module allows the caller to include limits for execution time and number
of bytes read from stdout and stderr.

# Usage

Please refer to the documentation of `POSIX::Spawn::Child` for the complete set
of options that can be passed when creating `Child`.

```ruby
require "em/posix/spawn"

EM.run {
p = EM::POSIX::Spawn::Child.new("echo something")

p.callback {
puts "Child process echo'd: #{p.out.inspect}"
EM.stop
}

p.errback { |err|
puts "Error running child process: #{err.inspect}"
EM.stop
}

# Add callbacks to listen to the child process' output streams.
listeners = p.add_streams_listener { |listener, data|
# Do something with the data.
# Use listener.name to get the name of the stream.
# Use listener.closed? to check if listener is closed.
# This block is called exactly once after the listener is closed.
}

# Optionally, wait for all the listeners to be closed.
while !listeners.all?(&:closed?) {
...
}

# Sends SIGTERM to the process, and SIGKILL after 5 seconds.
# Returns true if this kill was successful, false otherwise.
# The timeout is optional, default timeout is 0 (immediate SIGKILL
# after SIGTERM).
p.kill(5)
}
```

# Credit

The implementation for `EM::POSIX::Spawn::Child` and its tests are based on the
implementation and tests for `POSIX::Spawn::Child`, which is Copyright (c) 2011
by Ryan Tomayko <[email protected]> and Aman Gupta <[email protected]>.
7 changes: 7 additions & 0 deletions em-posix-spawn/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "bundler/gem_tasks"

require 'rake/testtask'

Rake::TestTask.new 'test' do |t|
t.test_files = FileList['test/test_*.rb']
end
21 changes: 21 additions & 0 deletions em-posix-spawn/em-posix-spawn.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "em/posix/spawn/version"

Gem::Specification.new do |s|
s.name = "em-posix-spawn"
s.version = EventMachine::POSIX::Spawn::VERSION

s.authors = ["Pieter Noordhuis"]
s.email = ["[email protected]"]
s.summary = "EventMachine-aware POSIX::Spawn::Child"

s.files = Dir.glob("lib/**/*")
s.test_files = Dir.glob("test/**/*")
s.require_paths = ["lib"]

s.add_runtime_dependency "eventmachine"
s.add_runtime_dependency "posix-spawn"
s.add_development_dependency "rake"
s.add_development_dependency "minitest"
end
1 change: 1 addition & 0 deletions em-posix-spawn/lib/em-posix-spawn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "em/posix/spawn"
2 changes: 2 additions & 0 deletions em-posix-spawn/lib/em/posix/spawn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "em/posix/spawn/version"
require "em/posix/spawn/child"
Loading

0 comments on commit 3916db2

Please sign in to comment.