Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the promise version of execFile #50

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,9 @@ const psOutputRegex = /^[ \t]*(?<pid>\d+)[ \t]+(?<ppid>\d+)[ \t]+(?<uid>\d+)[ \t
const nonWindowsSingleCall = async (options = {}) => {
const flags = options.all === false ? 'wwxo' : 'awwxo';

// TODO: Use the promise version of `execFile` when https://github.com/nodejs/node/issues/28244 is fixed.
const [psPid, stdout] = await new Promise((resolve, reject) => {
const child = childProcess.execFile('ps', [flags, psFields], {maxBuffer: TEN_MEGABYTES}, (error, stdout) => {
if (error === null) {
resolve([child.pid, stdout]);
} else {
reject(error);
}
});
});
const promise = execFile('ps', [flags, psFields], {maxBuffer: TEN_MEGABYTES});
const {stdout} = await promise;
const {pid: psPid} = promise.child;

const lines = stdout.trim().split('\n');
lines.shift();
Expand Down