0.2.0 • Published 8 years ago

spawn-manager v0.2.0

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

#spawn-manager module

This module contains the SpawnManager class and the spawnEvents enum. This module facilitates the management of creating sub processes using spawn.

API Documentation

Classes

Constants

Typedefs

SpawnManager

This class abstracts the way you interact with spawn functionality in node by providing events which you can optionally listen to or you can just get the result of executing your command. Check return details of runCommand method

Kind: global class

new SpawnManager()

create new SpawnManager

spawnManager.runCommand(cli, cmdArguments, cmdDir, cb)

execute a new command in a sub process (spawn). This class implements EventEmitter and fire certain events while executing the command. Please review spawnEvents for the list of emitted events

Kind: instance method of SpawnManager

ParamTypeDescription
clistringthe command name
cmdArgumentsArraycommand arguments
cmdDirstringpath to where the command will be executed. Pass null if you don't want to set it
cbcmdResultCallbackcallback function to be called after the command finish executing

Example

let manager = new SpawnManager();
let cmdOutput = '';
let exitCode;
manager.runCommand('ping', ['-c','4','localhost'], null, (err, result) => {
   // you can get the command exit code, stdout and stderr here in the result object
   exitCode = result.exitCode;
});
manager.on(SpawnManager.spawnEvents.stdoutChunk, (text) => {
   // you may want to subscribe to these events if you want to output the progress of a long running command for example but these subscription remains optional because you will get everything back in the result object
   cmdOutput += text;
});

spawnEvents : enum

Enum representing the events that will be fired by the SpawnManager.

Kind: global constant
Read only: true
Properties

NameTypeDefaultDescription
stdoutChunkstring"stdoutChunk"stdoutChunk represents a chunk of data returns from the command stdout
stderrChunkstring"stderrChunk"stderrChunk represents a chunk of data returns from the command stderr
errorstring"cmdError"error represents an error occurred while executing the command

cmdResultCallback : function

Callback to be called after the command finish executing.

Kind: global typedef

ParamTypeDescription
error*An object repenting an error.
theresultresult of executing the command

result : Object

Kind: global typedef
Properties

NameTypeDescription
stdoutValstringcommand stdout value
stderrValstringcommand stderr value
exitCodenumbercommand exit code
0.2.0

8 years ago

0.1.0

8 years ago