-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow for capture of stdout/stderr from worker (#425)
* feat: allow for capture of stdout/stderr from worker Signed-off-by: Chapman Pendery <cpendery@vt.edu> * fix: pr feedback Signed-off-by: Chapman Pendery <cpendery@vt.edu> * fix: small typo Signed-off-by: Chapman Pendery <cpendery@vt.edu> --------- Signed-off-by: Chapman Pendery <cpendery@vt.edu>
- Loading branch information
Showing
8 changed files
with
194 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var workerpool = require('..'); | ||
|
||
// create a worker pool using an the consoleWorker. This worker contains | ||
// console.log & console.error functions. | ||
var pool = workerpool.pool(__dirname + '/workers/consoleWorker.js', {emitStdStreams: true}); | ||
|
||
|
||
pool.exec('stdStreams', [], { | ||
on: function (payload) { | ||
if (payload.stdout) { | ||
console.log(`captured stdout: ${payload.stdout.trim()}`) // outputs 'captured stdout: stdout message' | ||
} | ||
if (payload.stderr) { | ||
console.log(`captured stderr: ${payload.stderr.trim()}`) // outputs 'captured stderr: stderr message' | ||
} | ||
}}) | ||
.then(function () { | ||
pool.terminate(); // terminate all workers when done | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// a simple worker | ||
var workerpool = require('../..'); | ||
|
||
function stdStreams() { | ||
console.log("stdout message") | ||
console.error("stderr message") | ||
return new Promise(function (resolve, reject) { | ||
resolve('done'); | ||
}); | ||
} | ||
|
||
// create a worker and register some functions | ||
workerpool.worker({ | ||
stdStreams: stdStreams, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// a simple worker | ||
var workerpool = require('../../'); | ||
|
||
function stdStreams() { | ||
console.log("stdout message") | ||
console.error("stderr message") | ||
return new Promise(function (resolve, reject) { | ||
resolve('done'); | ||
}); | ||
} | ||
|
||
// create a worker and register some functions | ||
workerpool.worker({ | ||
stdStreams: stdStreams, | ||
}); |