Skip to content

Instantly share code, notes, and snippets.

@hawx
Created May 8, 2012 11:47
Show Gist options
  • Save hawx/2634419 to your computer and use it in GitHub Desktop.
Save hawx/2634419 to your computer and use it in GitHub Desktop.
guard-shell with forking?
module Processes
extend self
def max
@max || 10
end
attr_writer :max
def processes
@processes ||= []
end
def can_fork_process?
Process.respond_to?(:fork) && max > 0
end
def fork(command)
if processes.size < max
processes << Process.fork { Process.exec *command }
else
process.delete Process.wait
fork command
end
end
def run(command)
if can_fork_process?
fork command
else
exec command
end
end
end
Processes.max = 5
guard :shell do
watch /.*/ do |m|
Processes.run "say #{m[0]}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment