@@ -15,12 +15,6 @@ const { isValidStatusCode, isValidUTF8 } = require('./validation');
1515const FastBuffer = Buffer [ Symbol . species ] ;
1616const promise = Promise . resolve ( ) ;
1717
18- //
19- // `queueMicrotask()` is not available in Node.js < 11.
20- //
21- const queueTask =
22- typeof queueMicrotask === 'function' ? queueMicrotask : queueMicrotaskShim ;
23-
2418const GET_INFO = 0 ;
2519const GET_PAYLOAD_LENGTH_16 = 1 ;
2620const GET_PAYLOAD_LENGTH_64 = 2 ;
@@ -577,7 +571,7 @@ class Receiver extends Writable {
577571 this . _state = GET_INFO ;
578572 } else {
579573 this . _state = DEFER_EVENT ;
580- queueTask ( ( ) => {
574+ setImmediate ( ( ) => {
581575 this . emit ( 'message' , data , true ) ;
582576 this . _state = GET_INFO ;
583577 this . startLoop ( cb ) ;
@@ -604,7 +598,7 @@ class Receiver extends Writable {
604598 this . _state = GET_INFO ;
605599 } else {
606600 this . _state = DEFER_EVENT ;
607- queueTask ( ( ) => {
601+ setImmediate ( ( ) => {
608602 this . emit ( 'message' , buf , false ) ;
609603 this . _state = GET_INFO ;
610604 this . startLoop ( cb ) ;
@@ -675,7 +669,7 @@ class Receiver extends Writable {
675669 this . _state = GET_INFO ;
676670 } else {
677671 this . _state = DEFER_EVENT ;
678- queueTask ( ( ) => {
672+ setImmediate ( ( ) => {
679673 this . emit ( this . _opcode === 0x09 ? 'ping' : 'pong' , data ) ;
680674 this . _state = GET_INFO ;
681675 this . startLoop ( cb ) ;
@@ -711,32 +705,3 @@ class Receiver extends Writable {
711705}
712706
713707module . 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