mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Document BufferedProcess and BufferedNodeProcess
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
BufferedProcess = require 'buffered-process'
|
||||
path = require 'path'
|
||||
|
||||
# Like BufferedProcess, but accepts a node script instead of an executable,
|
||||
# on Unix which allows running scripts and executables, this seems unnecessary,
|
||||
# but on Windows we have to separate scripts from executables since it doesn't
|
||||
# support shebang strings.
|
||||
# Private: Like BufferedProcess, but accepts a node script instead of an
|
||||
# executable, on Unix which allows running scripts and executables, this seems
|
||||
# unnecessary, but on Windows we have to separate scripts from executables since
|
||||
# it doesn't support shebang strings.
|
||||
module.exports =
|
||||
class BufferedNodeProcess extends BufferedProcess
|
||||
constructor: ({command, args, options, stdout, stderr, exit}) ->
|
||||
|
||||
@@ -2,11 +2,19 @@ ChildProcess = require 'child_process'
|
||||
path = require 'path'
|
||||
_ = require 'underscore'
|
||||
|
||||
# Private: A wrapper which provides buffering for ChildProcess
|
||||
module.exports =
|
||||
class BufferedProcess
|
||||
process: null
|
||||
killed: false
|
||||
|
||||
# options -
|
||||
# command: The command to execute.
|
||||
# args: The arguments for the given command.
|
||||
# options: The options to pass to ChildProcess.
|
||||
# stdout: The callback to receive stdout data.
|
||||
# stderr: The callback to receive stderr data.
|
||||
# exit: The callback to receive exit status.
|
||||
constructor: ({command, args, options, stdout, stderr, exit}={}) ->
|
||||
options ?= {}
|
||||
@process = ChildProcess.spawn(command, args, options)
|
||||
@@ -39,6 +47,13 @@ class BufferedProcess
|
||||
processExited = true
|
||||
triggerExitCallback()
|
||||
|
||||
# Private: Helper method to pass data line by line.
|
||||
#
|
||||
# stream - The Stream to read from.
|
||||
# onLines - The callback to call with each line of data.
|
||||
# onDone - The callback to call when the stream has closed.
|
||||
#
|
||||
# Returns nothing.
|
||||
bufferStream: (stream, onLines, onDone) ->
|
||||
stream.setEncoding('utf8')
|
||||
buffered = ''
|
||||
@@ -56,6 +71,9 @@ class BufferedProcess
|
||||
onLines(buffered) if buffered.length > 0
|
||||
onDone()
|
||||
|
||||
# Public: Terminates the process.
|
||||
#
|
||||
# Returns nothing.
|
||||
kill: ->
|
||||
@killed = true
|
||||
@process.kill()
|
||||
|
||||
Reference in New Issue
Block a user