-
Support EventTarget emitters in
events.once
from Node.js 12.11.0.Now you can use the
events.once
function with objects that implement the EventTarget interface. This interface is used widely in
the DOM and other web APIs.var events = require('events'); var assert = require('assert'); async function connect() { var ws = new WebSocket('wss://example.com'); await events.once(ws, 'open'); assert(ws.readyState === WebSocket.OPEN); } async function onClick() { await events.once(document.body, 'click'); alert('you clicked the page!'); }