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

Exit event #11

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,13 @@ Emitted when attempting to stop a Redis server.

#### close

Emitted once a Redis server has stopped.
Emitted once a Redis server has stopped. This only happens when `server.closed` is called,
not when the `child_process` fails on it's own (`redis-server` not found, for example).

#### exiting

Emmited when a Redis server is exiting or `child_process` exits with an error.

#### exit

Emmited when a Redis server exited (and `server.closed` was called).
10 changes: 8 additions & 2 deletions RedisServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,24 @@ class RedisServer extends events.EventEmitter {
else {
server.isClosing = true;

server.emit('closing');
server.emit('closing', result.err);
server.process.once('close', () => reject(result.err));
}
};

/**
* A listener to close the server when the current process exits.
* For the parameter list, please consult:
* https://nodejs.org/api/child_process.html#child_process_event_exit
* @argument {Number} [exitCode] final process exit code
* @argument {String} [signal] The signal by which the redis was terminated
* @return {undefined}
*/
const exitListener = () => {
const exitListener = (exitCode, signal) => {
server.emit('exiting', { exitCode, signal });
// istanbul ignore next
server.close();
server.emit('exit', { exitCode, signal });
};

server.emit('opening');
Expand Down