Class: LogToEvTransport
Extends
TransportStream
Constructors
new LogToEvTransport()
new LogToEvTransport(
opts
?):LogToEvTransport
Parameters
• opts?: any
Returns
Overrides
TransportStream.constructor
Properties
closed
readonly
closed:boolean
Is true after 'close' has been emitted.
Since
v8.0.0
Inherited from
TransportStream.closed
destroyed
destroyed:
boolean
Is true
after writable.destroy()
has been called.
Since
v8.0.0
Inherited from
TransportStream.destroyed
errored
readonly
errored:Error
Returns error if the stream has been destroyed with an error.
Since
v18.0.0
Inherited from
TransportStream.errored
format?
optional
format:Format
Inherited from
TransportStream.format
handleExceptions?
optional
handleExceptions:boolean
Inherited from
TransportStream.handleExceptions
handleRejections?
optional
handleRejections:boolean
Inherited from
TransportStream.handleRejections
level?
optional
level:string
Inherited from
TransportStream.level
silent?
optional
silent:boolean
Inherited from
TransportStream.silent
writable
readonly
writable:boolean
Is true
if it is safe to call writable.write()
, which means
the stream has not been destroyed, errored or ended.
Since
v11.4.0
Inherited from
TransportStream.writable
writableCorked
readonly
writableCorked:number
Number of times writable.uncork()
needs to be
called in order to fully uncork the stream.
Since
v13.2.0, v12.16.0
Inherited from
TransportStream.writableCorked
writableEnded
readonly
writableEnded:boolean
Is true
after writable.end()
has been called. This property
does not indicate whether the data has been flushed, for this use writable.writableFinished
instead.
Since
v12.9.0
Inherited from
TransportStream.writableEnded
writableFinished
readonly
writableFinished:boolean
Is set to true
immediately before the 'finish'
event is emitted.
Since
v12.6.0
Inherited from
TransportStream.writableFinished
writableHighWaterMark
readonly
writableHighWaterMark:number
Return the value of highWaterMark
passed when creating this Writable
.
Since
v9.3.0
Inherited from
TransportStream.writableHighWaterMark
writableLength
readonly
writableLength:number
This property contains the number of bytes (or objects) in the queue
ready to be written. The value provides introspection data regarding
the status of the highWaterMark
.
Since
v9.4.0
Inherited from
TransportStream.writableLength
writableNeedDrain
readonly
writableNeedDrain:boolean
Is true
if the stream's buffer has been full and stream will emit 'drain'.
Since
v15.2.0, v14.17.0
Inherited from
TransportStream.writableNeedDrain
writableObjectMode
readonly
writableObjectMode:boolean
Getter for the property objectMode
of a given Writable
stream.
Since
v12.3.0
Inherited from
TransportStream.writableObjectMode
captureRejectionSymbol
readonly
static
captureRejectionSymbol: typeofcaptureRejectionSymbol
Inherited from
TransportStream.captureRejectionSymbol
captureRejections
static
captureRejections:boolean
Sets or gets the default captureRejection value for all emitters.
Inherited from
TransportStream.captureRejections
defaultMaxListeners
static
defaultMaxListeners:number
Inherited from
TransportStream.defaultMaxListeners
errorMonitor
readonly
static
errorMonitor: typeoferrorMonitor
This symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular
'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an
'error'
event is emitted, therefore the process will still crash if no
regular 'error'
listener is installed.
Inherited from
TransportStream.errorMonitor
Methods
_construct()?
optional
_construct(callback
):void
Parameters
• callback
Returns
void
Inherited from
TransportStream._construct
_destroy()
_destroy(
error
,callback
):void
Parameters
• error: Error
• callback
Returns
void
Inherited from
TransportStream._destroy
_final()
_final(
callback
):void
Parameters
• callback
Returns
void
Inherited from
TransportStream._final
_write()
_write(
chunk
,encoding
,callback
):void
Parameters
• chunk: any
• encoding: BufferEncoding
• callback
Returns
void
Inherited from
TransportStream._write
_writev()?
optional
_writev(chunks
,callback
):void
Parameters
• chunks: object
[]
• callback
Returns
void
Inherited from
TransportStream._writev
addListener()
addListener(event, listener)
addListener(
event
,listener
):this
Event emitter The defined events on documents including:
- close
- drain
- error
- finish
- pipe
- unpipe
Parameters
• event: "close"
• listener
Returns
this
Inherited from
TransportStream.addListener
addListener(event, listener)
addListener(
event
,listener
):this
Alias for emitter.on(eventName, listener)
.
Parameters
• event: "drain"
• listener
Returns
this
Since
v0.1.26
Inherited from
TransportStream.addListener
addListener(event, listener)
addListener(
event
,listener
):this
Alias for emitter.on(eventName, listener)
.
Parameters
• event: "error"
• listener
Returns
this
Since
v0.1.26
Inherited from
TransportStream.addListener
addListener(event, listener)
addListener(
event
,listener
):this
Alias for emitter.on(eventName, listener)
.
Parameters
• event: "finish"
• listener
Returns
this
Since
v0.1.26
Inherited from
TransportStream.addListener
addListener(event, listener)
addListener(
event
,listener
):this
Alias for emitter.on(eventName, listener)
.
Parameters
• event: "pipe"
• listener
Returns
this
Since
v0.1.26
Inherited from
TransportStream.addListener
addListener(event, listener)
addListener(
event
,listener
):this
Alias for emitter.on(eventName, listener)
.
Parameters
• event: "unpipe"
• listener
Returns
this
Since
v0.1.26
Inherited from
TransportStream.addListener
addListener(event, listener)
addListener(
event
,listener
):this
Alias for emitter.on(eventName, listener)
.
Parameters
• event: string
| symbol
• listener
Returns
this
Since
v0.1.26
Inherited from
TransportStream.addListener
close()?
optional
close():void
Returns
void
Inherited from
TransportStream.close
cork()
cork():
void
The writable.cork()
method forces all written data to be buffered in memory.
The buffered data will be flushed when either the uncork or end methods are called.
The primary intent of writable.cork()
is to accommodate a situation in which
several small chunks are written to the stream in rapid succession. Instead of
immediately forwarding them to the underlying destination, writable.cork()
buffers all the chunks until writable.uncork()
is called, which will pass them
all to writable._writev()
, if present. This prevents a head-of-line blocking
situation where data is being buffered while waiting for the first small chunk
to be processed. However, use of writable.cork()
without implementingwritable._writev()
may have an adverse effect on throughput.
See also: writable.uncork()
, writable._writev()
.
Returns
void
Since
v0.11.2
Inherited from
TransportStream.cork
destroy()
destroy(
error
?):this
Destroy the stream. Optionally emit an 'error'
event, and emit a 'close'
event (unless emitClose
is set to false
). After this call, the writable
stream has ended and subsequent calls to write()
or end()
will result in
an ERR_STREAM_DESTROYED
error.
This is a destructive and immediate way to destroy a stream. Previous calls towrite()
may not have drained, and may trigger an ERR_STREAM_DESTROYED
error.
Use end()
instead of destroy if data should flush before close, or wait for
the 'drain'
event before destroying the stream.
Once destroy()
has been called any further calls will be a no-op and no
further errors except from _destroy()
may be emitted as 'error'
.
Implementors should not override this method,
but instead implement writable._destroy()
.
Parameters
• error?: Error
Optional, an error to emit with 'error'
event.
Returns
this
Since
v8.0.0
Inherited from
TransportStream.destroy
emit()
emit(event)
emit(
event
):boolean
Synchronously calls each of the listeners registered for the event namedeventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Parameters
• event: "close"
Returns
boolean
Since
v0.1.26
Inherited from
TransportStream.emit
emit(event)
emit(
event
):boolean
Synchronously calls each of the listeners registered for the event namedeventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Parameters
• event: "drain"
Returns
boolean
Since
v0.1.26
Inherited from
TransportStream.emit
emit(event, err)
emit(
event
,err
):boolean
Synchronously calls each of the listeners registered for the event namedeventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Parameters
• event: "error"
• err: Error
Returns
boolean
Since
v0.1.26
Inherited from
TransportStream.emit
emit(event)
emit(
event
):boolean
Synchronously calls each of the listeners registered for the event namedeventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Parameters
• event: "finish"
Returns
boolean
Since
v0.1.26
Inherited from
TransportStream.emit
emit(event, src)
emit(
event
,src
):boolean
Synchronously calls each of the listeners registered for the event namedeventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Parameters
• event: "pipe"
• src: Readable
Returns
boolean
Since
v0.1.26
Inherited from
TransportStream.emit
emit(event, src)
emit(
event
,src
):boolean
Synchronously calls each of the listeners registered for the event namedeventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Parameters
• event: "unpipe"
• src: Readable
Returns
boolean
Since
v0.1.26
Inherited from
TransportStream.emit
emit(event, args)
emit(
event
, ...args
):boolean
Synchronously calls each of the listeners registered for the event namedeventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Parameters
• event: string
| symbol
• ...args: any
[]
Returns
boolean
Since
v0.1.26
Inherited from
TransportStream.emit
end()
end(cb)
end(
cb
?):this
Calling the writable.end()
method signals that no more data will be written
to the Writable
. The optional chunk
and encoding
arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
Calling the write method after calling end will raise an error.
// Write 'hello, ' and then end with 'world!'.
const fs = require('fs');
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
Parameters
• cb?
Returns
this
Since
v0.9.4
Inherited from
TransportStream.end
end(chunk, cb)
end(
chunk
,cb
?):this
Parameters
• chunk: any
• cb?
Returns
this
Inherited from
TransportStream.end
end(chunk, encoding, cb)
end(
chunk
,encoding
,cb
?):this
Parameters
• chunk: any
• encoding: BufferEncoding
• cb?
Returns
this
Inherited from
TransportStream.end
eventNames()
eventNames(): (
string
|symbol
)[]
Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbol
s.
const EventEmitter = require('events');
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
Returns
(string
| symbol
)[]
Since
v6.0.0
Inherited from
TransportStream.eventNames
getMaxListeners()
getMaxListeners():
number
Returns the current max listener value for the EventEmitter
which is either
set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
Returns
number
Since
v1.0.0
Inherited from
TransportStream.getMaxListeners
listenerCount()
listenerCount(
eventName
):number
Returns the number of listeners listening to the event named eventName
.
Parameters
• eventName: string
| symbol
The name of the event being listened for
Returns
number
Since
v3.2.0
Inherited from
TransportStream.listenerCount
listeners()
listeners(
eventName
):Function
[]
Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
Parameters
• eventName: string
| symbol
Returns
Function
[]
Since
v0.1.26
Inherited from
TransportStream.listeners
log()
log(
info
,callback
):any
Parameters
• info: any
• callback: any
Returns
any
Overrides
TransportStream.log
logv()?
optional
logv(info
,next
):any
Parameters
• info: any
• next
Returns
any
Inherited from
TransportStream.logv
off()
off(
eventName
,listener
):this
Alias for emitter.removeListener()
.
Parameters
• eventName: string
| symbol
• listener
Returns
this
Since
v10.0.0
Inherited from
TransportStream.off
on()
on(event, listener)
on(
event
,listener
):this
Adds the listener
function to the end of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Parameters
• event: "close"
• listener
The callback function
Returns
this
Since
v0.1.101
Inherited from
TransportStream.on
on(event, listener)
on(
event
,listener
):this
Adds the listener
function to the end of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Parameters
• event: "drain"
• listener
The callback function
Returns
this
Since
v0.1.101
Inherited from
TransportStream.on
on(event, listener)
on(
event
,listener
):this
Adds the listener
function to the end of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Parameters
• event: "error"
• listener
The callback function
Returns
this
Since
v0.1.101
Inherited from
TransportStream.on
on(event, listener)
on(
event
,listener
):this
Adds the listener
function to the end of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Parameters
• event: "finish"
• listener
The callback function
Returns
this
Since
v0.1.101
Inherited from
TransportStream.on
on(event, listener)
on(
event
,listener
):this
Adds the listener
function to the end of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Parameters
• event: "pipe"
• listener
The callback function
Returns
this
Since
v0.1.101
Inherited from
TransportStream.on
on(event, listener)
on(
event
,listener
):this
Adds the listener
function to the end of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Parameters
• event: "unpipe"
• listener
The callback function
Returns
this
Since
v0.1.101
Inherited from
TransportStream.on
on(event, listener)
on(
event
,listener
):this
Adds the listener
function to the end of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Parameters
• event: string
| symbol
• listener
The callback function
Returns
this
Since
v0.1.101
Inherited from
TransportStream.on
once()
once(event, listener)
once(
event
,listener
):this
Adds a one-timelistener
function for the event named eventName
. The
next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependOnceListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Parameters
• event: "close"
• listener
The callback function
Returns
this
Since
v0.3.0
Inherited from
TransportStream.once
once(event, listener)
once(
event
,listener
):this
Adds a one-timelistener
function for the event named eventName
. The
next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependOnceListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Parameters
• event: "drain"
• listener
The callback function
Returns
this
Since
v0.3.0