Skip to content

Commit a72bb9a

Browse files
committed
PROTON-2879: [Python] Added accessors to unsettled deliveries
Added unsettled delivery accessors to high level python binding. Including a generator which should make iterating over all unsettled deliveries of a link straightforward.
1 parent ff330a6 commit a72bb9a

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

python/proton/_delivery.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
pn_transactional_disposition_get_id,
4949
pn_transactional_disposition_set_id,
5050
pn_transactional_disposition_get_outcome_type,
51-
pn_transactional_disposition_set_outcome_type)
51+
pn_transactional_disposition_set_outcome_type,
52+
pn_unsettled_next)
5253

5354
from ._condition import cond2obj, obj2cond, Condition
5455
from ._data import dat2obj, obj2dat
@@ -659,6 +660,14 @@ def settle(self) -> None:
659660
"""
660661
pn_delivery_settle(self._impl)
661662

663+
@property
664+
def unsettled_next(self) -> Optional['Delivery']:
665+
"""
666+
The next unsettled delivery on the link or ``None`` if there are
667+
no more unsettled deliveries.
668+
"""
669+
return Delivery.wrap(pn_unsettled_next(self._impl))
670+
662671
@property
663672
def aborted(self) -> bool:
664673
"""

python/proton/_endpoints.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
pn_terminus_is_dynamic, pn_terminus_outcomes, pn_terminus_properties, pn_terminus_set_address, \
5555
pn_terminus_set_distribution_mode, pn_terminus_set_durability, pn_terminus_set_dynamic, \
5656
pn_terminus_set_expiry_policy, pn_terminus_set_timeout, pn_terminus_set_type, \
57-
pn_link_properties, pn_link_remote_properties
57+
pn_link_properties, pn_link_remote_properties, pn_unsettled_head
5858

5959
from ._condition import cond2obj, obj2cond
6060
from ._data import Data, dat2obj, obj2dat, PropertyDict, SymbolList
@@ -63,7 +63,7 @@
6363
from ._handler import Handler
6464
from ._transport import Transport
6565
from ._wrapper import Wrapper
66-
from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING
66+
from typing import Any, Dict, Generator, List, Optional, Union, TYPE_CHECKING
6767

6868
if TYPE_CHECKING:
6969
from ._condition import Condition
@@ -888,6 +888,28 @@ def unsettled(self) -> int:
888888
"""
889889
return pn_link_unsettled(self._impl)
890890

891+
@property
892+
def unsettled_head(self) -> Optional[Delivery]:
893+
"""
894+
The first unsettled delivery for this link.
895+
896+
This operation will return the first unsettled delivery on the
897+
link, or ``None`` if there are no unsettled deliveries.
898+
"""
899+
return Delivery.wrap(pn_unsettled_head(self._impl))
900+
901+
@property
902+
def unsettled_deliveries(self) -> Generator[Delivery]:
903+
"""
904+
Returns a generator of unsettled deliveries for this link.
905+
906+
:return: Generator of unsettled deliveries.
907+
"""
908+
delivery = self.unsettled_head
909+
while delivery:
910+
yield delivery
911+
delivery = delivery.unsettled_next
912+
891913
@property
892914
def credit(self) -> int:
893915
"""

0 commit comments

Comments
 (0)