@@ -511,18 +511,14 @@ async def put(self, item: T) -> None:
511511 async with parent ._async_not_full :
512512 with parent ._sync_mutex :
513513 parent ._get_loop () # check the event loop
514- if parent ._maxsize > 0 :
515- do_wait = True
516- while do_wait :
517- do_wait = parent ._qsize () >= parent ._maxsize
518- if do_wait :
519- parent ._async_not_full_waiting += 1
520- parent ._sync_mutex .release ()
521- try :
522- await parent ._async_not_full .wait ()
523- finally :
524- parent ._sync_mutex .acquire ()
525- parent ._async_not_full_waiting -= 1
514+ while 0 < parent ._maxsize <= parent ._qsize ():
515+ parent ._async_not_full_waiting += 1
516+ parent ._sync_mutex .release ()
517+ try :
518+ await parent ._async_not_full .wait ()
519+ finally :
520+ parent ._sync_mutex .acquire ()
521+ parent ._async_not_full_waiting -= 1
526522
527523 parent ._put_internal (item )
528524 if parent ._async_not_empty_waiting :
@@ -539,9 +535,8 @@ def put_nowait(self, item: T) -> None:
539535 parent ._check_closing ()
540536 with parent ._sync_mutex :
541537 loop = parent ._get_loop ()
542- if parent ._maxsize > 0 :
543- if parent ._qsize () >= parent ._maxsize :
544- raise AsyncQueueFull
538+ if 0 < parent ._maxsize <= parent ._qsize ():
539+ raise AsyncQueueFull
545540
546541 parent ._put_internal (item )
547542 if parent ._async_not_empty_waiting :
@@ -561,18 +556,14 @@ async def get(self) -> T:
561556 async with parent ._async_not_empty :
562557 with parent ._sync_mutex :
563558 parent ._get_loop () # check the event loop
564- do_wait = True
565- while do_wait :
566- do_wait = parent ._qsize () == 0
567-
568- if do_wait :
569- parent ._async_not_empty_waiting += 1
570- parent ._sync_mutex .release ()
571- try :
572- await parent ._async_not_empty .wait ()
573- finally :
574- parent ._sync_mutex .acquire ()
575- parent ._async_not_empty_waiting -= 1
559+ while not parent ._qsize ():
560+ parent ._async_not_empty_waiting += 1
561+ parent ._sync_mutex .release ()
562+ try :
563+ await parent ._async_not_empty .wait ()
564+ finally :
565+ parent ._sync_mutex .acquire ()
566+ parent ._async_not_empty_waiting -= 1
576567
577568 item = parent ._get ()
578569 if parent ._async_not_full_waiting :
@@ -589,7 +580,7 @@ def get_nowait(self) -> T:
589580 parent = self ._parent
590581 parent ._check_closing ()
591582 with parent ._sync_mutex :
592- if parent ._qsize () == 0 :
583+ if not parent ._qsize ():
593584 raise AsyncQueueEmpty
594585
595586 loop = parent ._get_loop ()
0 commit comments