嗨,大家好,每次发出事件时,我如何才能兑现承诺 代码如下:
connect() {
return new Promise( ( resolve, reject ) => {
this.wss.on( 'connection', ws => {
ws.on( 'message', ( message ) => {
log.debug( `Received << ${ message } `);
return resolve( {event: 'message', conn: ws, message: message} );
)}
ws.on( 'error', ( err ) => {
log.error( `Error on ${ Utility.stringifyWebSocket(ws) } : ${ err } ` );
return reject( {event: 'error', err: err} );
});
});
conn.connect()
.then( result => {
connector.publish(message);
} )
我想在每次消息发送时发布消息,现在它只处理一条消息,返回仅被调用一次