@@ -56,6 +56,7 @@ const {
5656const {
5757 codes : {
5858 ERR_INVALID_ARG_TYPE ,
59+ ERR_INVALID_ARG_VALUE ,
5960 ERR_INVALID_RETURN_VALUE ,
6061 ERR_OUT_OF_RANGE ,
6162 } ,
@@ -588,11 +589,6 @@ class SyncShareImpl {
588589 throw new ERR_OUT_OF_RANGE (
589590 'buffered bytes' , `< ${ self . #options. budget } ` ,
590591 self . #bufferedBytes) ;
591- case 'unbounded' :
592- throw new ERR_OUT_OF_RANGE (
593- 'buffered bytes' , `< ${ self . #options. budget } ` +
594- '(unbounded not available in sync context)' ,
595- self . #bufferedBytes) ;
596592 case 'drop-oldest' :
597593 while ( self . #bufferedBytes >= self . #options. budget &&
598594 self . #buffer. length > 0 ) {
@@ -609,9 +605,13 @@ class SyncShareImpl {
609605 self . #recomputeMinCursor( ) ;
610606 break ;
611607 case 'drop-newest' :
612- state . detached = true ;
613- self . #deleteConsumer( state ) ;
614- return { __proto__ : null , done : true , value : undefined } ;
608+ while ( self . #bufferedBytes >= self . #options. budget &&
609+ ! self . #sourceExhausted &&
610+ ! self . #cancelled &&
611+ self . #sourceError === kNoShareError ) {
612+ self . #pullFromSource( true ) ;
613+ }
614+ break ;
615615 }
616616 }
617617
@@ -694,7 +694,7 @@ class SyncShareImpl {
694694 this . cancel ( ) ;
695695 }
696696
697- #pullFromSource( ) {
697+ #pullFromSource( discard = false ) {
698698 if ( this . #sourceExhausted || this . #cancelled) return ;
699699
700700 try {
@@ -704,7 +704,7 @@ class SyncShareImpl {
704704
705705 if ( result . done ) {
706706 this . #sourceExhausted = true ;
707- } else {
707+ } else if ( ! discard ) {
708708 const entry = createBatchEntry ( result . value ) ;
709709 this . #buffer. push ( entry ) ;
710710 this . #bufferedBytes += entry . byteLength ;
@@ -814,6 +814,11 @@ function shareSync(source, options = { __proto__: null }) {
814814 backpressure = 'strict' ,
815815 } = options ;
816816 validateInteger ( budget , 'options.budget' , 16384 ) ;
817+ if ( backpressure === 'unbounded' ) {
818+ throw new ERR_INVALID_ARG_VALUE (
819+ 'options.backpressure' , backpressure ,
820+ 'unbounded is not supported by shareSync()' ) ;
821+ }
817822
818823 const opts = {
819824 __proto__ : null ,
0 commit comments