@@ -13,13 +13,6 @@ const { concat, toArrayBuffer, unmask } = require('./buffer-util');
1313const { isValidStatusCode, isValidUTF8 } = require ( './validation' ) ;
1414
1515const FastBuffer = Buffer [ Symbol . species ] ;
16- const promise = Promise . resolve ( ) ;
17-
18- //
19- // `queueMicrotask()` is not available in Node.js < 11.
20- //
21- const queueTask =
22- typeof queueMicrotask === 'function' ? queueMicrotask : queueMicrotaskShim ;
2316
2417const GET_INFO = 0 ;
2518const GET_PAYLOAD_LENGTH_16 = 1 ;
@@ -577,7 +570,7 @@ class Receiver extends Writable {
577570 this . _state = GET_INFO ;
578571 } else {
579572 this . _state = DEFER_EVENT ;
580- queueTask ( ( ) => {
573+ setImmediate ( ( ) => {
581574 this . emit ( 'message' , data , true ) ;
582575 this . _state = GET_INFO ;
583576 this . startLoop ( cb ) ;
@@ -604,7 +597,7 @@ class Receiver extends Writable {
604597 this . _state = GET_INFO ;
605598 } else {
606599 this . _state = DEFER_EVENT ;
607- queueTask ( ( ) => {
600+ setImmediate ( ( ) => {
608601 this . emit ( 'message' , buf , false ) ;
609602 this . _state = GET_INFO ;
610603 this . startLoop ( cb ) ;
@@ -675,7 +668,7 @@ class Receiver extends Writable {
675668 this . _state = GET_INFO ;
676669 } else {
677670 this . _state = DEFER_EVENT ;
678- queueTask ( ( ) => {
671+ setImmediate ( ( ) => {
679672 this . emit ( this . _opcode === 0x09 ? 'ping' : 'pong' , data ) ;
680673 this . _state = GET_INFO ;
681674 this . startLoop ( cb ) ;
@@ -711,32 +704,3 @@ class Receiver extends Writable {
711704}
712705
713706module . exports = Receiver ;
714-
715- /**
716- * A shim for `queueMicrotask()`.
717- *
718- * @param {Function } cb Callback
719- */
720- function queueMicrotaskShim ( cb ) {
721- promise . then ( cb ) . catch ( throwErrorNextTick ) ;
722- }
723-
724- /**
725- * Throws an error.
726- *
727- * @param {Error } err The error to throw
728- * @private
729- */
730- function throwError ( err ) {
731- throw err ;
732- }
733-
734- /**
735- * Throws an error in the next tick.
736- *
737- * @param {Error } err The error to throw
738- * @private
739- */
740- function throwErrorNextTick ( err ) {
741- process . nextTick ( throwError , err ) ;
742- }
0 commit comments