Method description:
Register a single listener for the specified event, so the listener will only trigger once at most, and the listener will be released immediately after triggering.
Grammar:
emitter.once(event, listener)
Receive parameters:
event (string) Event type
listener (function) The callback function when an event is triggered
Example:
server.once('connection', function (stream) {
console.log('Ah, we have our first user!');
});
Source code:
EventEmitter.prototype.once = function(type, listener) {
if (!util.isFunction(listener))
Throw TypeError('listener must be a function');
function g() {
This.removeListener(type, g);
Listener.apply(this, arguments);
}
g.listener = listener;
this.on(type, g);
return this;
};
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn