@@ -84,7 +84,7 @@ class Assembler:
84
84
# coverage reports incorrectly: "line NN didn't jump to the function exit"
85
85
def __init__ ( # pragma: no cover
86
86
self ,
87
- high : int = 16 ,
87
+ high : int | None = None ,
88
88
low : int | None = None ,
89
89
pause : Callable [[], Any ] = lambda : None ,
90
90
resume : Callable [[], Any ] = lambda : None ,
@@ -96,12 +96,15 @@ def __init__( # pragma: no cover
96
96
# call to Protocol.data_received() could produce thousands of frames,
97
97
# which must be buffered. Instead, we pause reading when the buffer goes
98
98
# above the high limit and we resume when it goes under the low limit.
99
- if low is None :
99
+ if high is not None and low is None :
100
100
low = high // 4
101
- if low < 0 :
102
- raise ValueError ("low must be positive or equal to zero" )
103
- if high < low :
104
- raise ValueError ("high must be greater than or equal to low" )
101
+ if high is None and low is not None :
102
+ high = low * 4
103
+ if high is not None and low is not None :
104
+ if low < 0 :
105
+ raise ValueError ("low must be positive or equal to zero" )
106
+ if high < low :
107
+ raise ValueError ("high must be greater than or equal to low" )
105
108
self .high , self .low = high , low
106
109
self .pause = pause
107
110
self .resume = resume
@@ -256,13 +259,21 @@ def put(self, frame: Frame) -> None:
256
259
257
260
def maybe_pause (self ) -> None :
258
261
"""Pause the writer if queue is above the high water mark."""
262
+ # Skip if flow control is disabled
263
+ if self .high is None :
264
+ return
265
+
259
266
# Check for "> high" to support high = 0
260
267
if len (self .frames ) > self .high and not self .paused :
261
268
self .paused = True
262
269
self .pause ()
263
270
264
271
def maybe_resume (self ) -> None :
265
272
"""Resume the writer if queue is below the low water mark."""
273
+ # Skip if flow control is disabled
274
+ if self .low is None :
275
+ return
276
+
266
277
# Check for "<= low" to support low = 0
267
278
if len (self .frames ) <= self .low and self .paused :
268
279
self .paused = False
0 commit comments