connection.addListener(event, listener) connection.on(event, listener) connection.once(event, listener) connection.removeListener(event, listener) connection.removeAllListeners([event]) connection.setMaxListeners(n) connection.listeners(event) connection.emit(event, [arg1], [arg2], [...])
Connections implement the same interface as Node’s EventEmitter. This allows you to listen for changes in connection state.
Four events are emitted: connect
, close
, timeout
and error
.
connect
: a successful connection to the server.close
: the connection has been closed, either through an error or by calling connection.close()
.timeout
: the underlying socket has timed out.error
: a protocol-level error has occurred. (This will not be sent on a query error; those are returned to callbacks/promises.)Example: Monitor the connection state with events.
r.connect({}, function(err, conn) { if (err) throw err; conn.addListener('error', function(e) { processNetworkError(e); }); conn.addListener('close', function() { cleanup(); }); runQueries(conn); });
Example: As in Node, on
is a synonym for addListener
.
conn.on('close', function() { cleanup(); }); conn.close();
Couldn't find what you were looking for?
© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/javascript/event_emitter/