trait ReadableStream extends Object with StObject with EventEmitter
- Annotations
- @JSType() @native()
- Alphabetic
- By Inheritance
- ReadableStream
- EventEmitter
- StObject
- Object
- Any
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def addListener(eventName: Symbol, listener: Function1[Any, Unit]): ReadableStream.this.type
- Definition Classes
- EventEmitter
- def addListener(eventName: String, listener: Function1[Any, Unit]): ReadableStream.this.type
Alias for
emitter.on(eventName, listener)
.Alias for
emitter.on(eventName, listener)
.- Definition Classes
- EventEmitter
- Since
v0.1.26
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def emit(eventName: Symbol, args: Any*): Boolean
- Definition Classes
- EventEmitter
- def emit(eventName: String, args: Any*): Boolean
Synchronously calls each of the listeners registered for the event named
eventName
, in the order they were registered, passing the supplied arguments to each.Synchronously calls each of the listeners registered for the event named
eventName
, in the order they were registered, passing the supplied arguments to each.Returns
true
if the event had listeners,false
otherwise.js 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
- Definition Classes
- EventEmitter
- Since
v0.1.26
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def eventNames(): Array[|[String, Symbol]]
Returns an array listing the events for which the emitter has registered listeners.
Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or
Symbol
s.js 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) ]
- Definition Classes
- EventEmitter
- Since
v6.0.0
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def getMaxListeners(): Double
Returns the current max listener value for the
EventEmitter
which is either set byemitter.setMaxListeners(n)
or defaults todefaultMaxListeners
.Returns the current max listener value for the
EventEmitter
which is either set byemitter.setMaxListeners(n)
or defaults todefaultMaxListeners
.- Definition Classes
- EventEmitter
- Since
v1.0.0
- def hasOwnProperty(v: String): Boolean
- Definition Classes
- Object
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isPaused(): Boolean
- def isPrototypeOf(v: Object): Boolean
- Definition Classes
- Object
- def listenerCount(eventName: Symbol): Double
- Definition Classes
- EventEmitter
- def listenerCount(eventName: String): Double
Returns the number of listeners listening to the event named
eventName
.Returns the number of listeners listening to the event named
eventName
.- eventName
The name of the event being listened for
- Definition Classes
- EventEmitter
- Since
v3.2.0
- def listeners(eventName: Symbol): Array[Function]
- Definition Classes
- EventEmitter
- def listeners(eventName: String): Array[Function]
Returns a copy of the array of listeners for the event named
eventName
.Returns a copy of the array of listeners for the event named
eventName
.js server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ]
- Definition Classes
- EventEmitter
- Since
v0.1.26
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def off(eventName: Symbol, listener: Function1[Any, Unit]): ReadableStream.this.type
- Definition Classes
- EventEmitter
- def off(eventName: String, listener: Function1[Any, Unit]): ReadableStream.this.type
Alias for
emitter.removeListener()
.Alias for
emitter.removeListener()
.- Definition Classes
- EventEmitter
- Since
v10.0.0
- def on(eventName: Symbol, listener: Function1[Any, Unit]): ReadableStream.this.type
- Definition Classes
- EventEmitter
- def on(eventName: String, listener: Function1[Any, Unit]): ReadableStream.this.type
Adds the
listener
function to the end of the listeners array for the event namedeventName
.Adds the
listener
function to the end of the listeners array for the event namedeventName
. No checks are made to see if thelistener
has already been added. Multiple calls passing the same combination ofeventName
andlistener
will result in thelistener
being added, and called, multiple times.js 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. The
emitter.prependListener()
method can be used as an alternative to add the event listener to the beginning of the listeners array.js const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a
- eventName
The name of the event.
- listener
The callback function
- Definition Classes
- EventEmitter
- Since
v0.1.101
- def once(eventName: Symbol, listener: Function1[Any, Unit]): ReadableStream.this.type
- Definition Classes
- EventEmitter
- def once(eventName: String, listener: Function1[Any, Unit]): ReadableStream.this.type
Adds a **one-time**
listener
function for the event namedeventName
.Adds a **one-time**
listener
function for the event namedeventName
. The next timeeventName
is triggered, this listener is removed and then invoked.js 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. The
emitter.prependOnceListener()
method can be used as an alternative to add the event listener to the beginning of the listeners array.js const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a
- eventName
The name of the event.
- listener
The callback function
- Definition Classes
- EventEmitter
- Since
v0.3.0
- def pause(): ReadableStream.this.type
- def pipe[T](destination: T, options: End): T
- def pipe[T](destination: T): T
- def prependListener(eventName: Symbol, listener: Function1[Any, Unit]): ReadableStream.this.type
- Definition Classes
- EventEmitter
- def prependListener(eventName: String, listener: Function1[Any, Unit]): ReadableStream.this.type
Adds the
listener
function to the _beginning_ of the listeners array for the event namedeventName
.Adds the
listener
function to the _beginning_ of the listeners array for the event namedeventName
. No checks are made to see if thelistener
has already been added. Multiple calls passing the same combination ofeventName
andlistener
will result in thelistener
being added, and called, multiple times.js server.prependListener('connection', (stream) => { console.log('someone connected!'); });
Returns a reference to the
EventEmitter
, so that calls can be chained.- eventName
The name of the event.
- listener
The callback function
- Definition Classes
- EventEmitter
- Since
v6.0.0
- def prependOnceListener(eventName: Symbol, listener: Function1[Any, Unit]): ReadableStream.this.type
- Definition Classes
- EventEmitter
- def prependOnceListener(eventName: String, listener: Function1[Any, Unit]): ReadableStream.this.type
Adds a **one-time**
listener
function for the event namedeventName
to the_beginning_ of the listeners array.Adds a **one-time**
listener
function for the event namedeventName
to the_beginning_ of the listeners array. The next timeeventName
is triggered, this listener is removed, and then invoked.js server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); });
Returns a reference to the
EventEmitter
, so that calls can be chained.- eventName
The name of the event.
- listener
The callback function
- Definition Classes
- EventEmitter
- Since
v6.0.0
- def propertyIsEnumerable(v: String): Boolean
- Definition Classes
- Object
- def rawListeners(eventName: Symbol): Array[Function]
- Definition Classes
- EventEmitter
- def rawListeners(eventName: String): Array[Function]
Returns a copy of the array of listeners for the event named
eventName
, including any wrappers (such as those created by.once()
).Returns a copy of the array of listeners for the event named
eventName
, including any wrappers (such as those created by.once()
).js const emitter = new EventEmitter(); emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function
onceWrapper
which has a property //listener
which contains the original listener bound above const listeners = emitter.rawListeners('log'); const logFnWrapper = listeners[0];// Logs "log once" to the console and does not unbind the
once
event logFnWrapper.listener();// Logs "log once" to the console and removes the listener logFnWrapper();
emitter.on('log', () => console.log('log persistently')); // Will return a new Array with a single function bound by
.on()
above const newListeners = emitter.rawListeners('log');// Logs "log persistently" twice newListeners[0](); emitter.emit('log');
- Definition Classes
- EventEmitter
- Since
v9.4.0
- def read(size: Double): |[String, Buffer]
- def read(): |[String, Buffer]
- val readable: Boolean
- def removeAllListeners(event: Symbol): ReadableStream.this.type
- Definition Classes
- EventEmitter
- def removeAllListeners(event: String): ReadableStream.this.type
- Definition Classes
- EventEmitter
- def removeAllListeners(): ReadableStream.this.type
Removes all listeners, or those of the specified
eventName
.Removes all listeners, or those of the specified
eventName
.It is bad practice to remove listeners added elsewhere in the code, particularly when the
EventEmitter
instance was created by some other component or module (e.g. sockets or file streams).Returns a reference to the
EventEmitter
, so that calls can be chained.- Definition Classes
- EventEmitter
- Since
v0.1.26
- def removeListener(eventName: Symbol, listener: Function1[Any, Unit]): ReadableStream.this.type
- Definition Classes
- EventEmitter
- def removeListener(eventName: String, listener: Function1[Any, Unit]): ReadableStream.this.type
Removes the specified
listener
from the listener array for the event namedeventName
.Removes the specified
listener
from the listener array for the event namedeventName
.js const callback = (stream) => { console.log('someone connected!'); }; server.on('connection', callback); // ... server.removeListener('connection', callback);
removeListener()
will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specifiedeventName
, thenremoveListener()
must be called multiple times to remove each instance.Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any
removeListener()
orremoveAllListeners()
calls _after_ emitting and_before_ the last listener finishes execution will not remove them fromemit()
in progress. Subsequent events behave as expected.js const myEmitter = new MyEmitter();
const callbackA = () => { console.log('A'); myEmitter.removeListener('event', callbackB); };
const callbackB = () => { console.log('B'); };
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called. // Internal listener array at time of emit [callbackA, callbackB] myEmitter.emit('event'); // Prints: // A // B
// callbackB is now removed. // Internal listener array [callbackA] myEmitter.emit('event'); // Prints: // A
Because listeners are managed using an internal array, calling this will change the position indices of any listener registered _after_ the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the
emitter.listeners()
method will need to be recreated.When a single function has been added as a handler multiple times for a single event (as in the example below),
removeListener()
will remove the most recently added instance. In the example theonce('ping')
listener is removed:js const ee = new EventEmitter();
function pong() { console.log('pong'); }
ee.on('ping', pong); ee.once('ping', pong); ee.removeListener('ping', pong);
ee.emit('ping'); ee.emit('ping');
Returns a reference to the
EventEmitter
, so that calls can be chained.- Definition Classes
- EventEmitter
- Since
v0.1.26
- def resume(): ReadableStream.this.type
- def setEncoding(encoding: BufferEncoding): ReadableStream.this.type
- def setMaxListeners(n: Double): ReadableStream.this.type
By default
EventEmitter
s will print a warning if more than10
listeners are added for a particular event.By default
EventEmitter
s will print a warning if more than10
listeners are added for a particular event. This is a useful default that helps finding memory leaks. Theemitter.setMaxListeners()
method allows the limit to be modified for this specificEventEmitter
instance. The value can be set toInfinity
(or0
) to indicate an unlimited number of listeners.Returns a reference to the
EventEmitter
, so that calls can be chained.- Definition Classes
- EventEmitter
- Since
v0.3.5
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toLocaleString(): String
- Definition Classes
- Object
- def toString(): String
- Definition Classes
- AnyRef → Any
- def unpipe(destination: WritableStream): ReadableStream.this.type
- def unpipe(): ReadableStream.this.type
- def unshift(chunk: Uint8Array, encoding: BufferEncoding): Unit
- def unshift(chunk: Uint8Array): Unit
- def unshift(chunk: String, encoding: BufferEncoding): Unit
- def unshift(chunk: String): Unit
- def valueOf(): Any
- Definition Classes
- Object
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def wrap(oldStream: ReadableStream): ReadableStream.this.type
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated