Skip to content

Commit

Permalink
Updated as per review
Browse files Browse the repository at this point in the history
Left in getTransaction as pop() is needed different to FIFO's pop(0)
  • Loading branch information
pazzarpj committed Dec 3, 2018
1 parent d1f2923 commit fd1b8a3
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,40 +436,12 @@ def delTransaction(self, tid):
if self.transactions: self.transactions.pop(0)


class LatestTransactionManager(ModbusTransactionManager):
class LatestTransactionManager(FifoTransactionManager):
""" Implements a transaction for a manager where the
results is the latest transaction only. This can be used where only the
latest transaction matters.
"""

def __init__(self, client, **kwargs):
""" Initializes an instance of the ModbusTransactionManager
:param client: The client socket wrapper
"""
super(LatestTransactionManager, self).__init__(client, **kwargs)
self.transactions = []

def __iter__(self):
""" Iterater over the current managed transactions
:returns: An iterator of the managed transactions
"""
return iter(self.transactions)

def addTransaction(self, request, tid=None):
""" Adds a transaction to the handler
This holds the requests in case it needs to be resent.
After being sent, the request is removed.
:param request: The request to hold on to
:param tid: The overloaded transaction id to use
"""
tid = tid if tid is not None else request.transaction_id
_logger.debug("Adding transaction %d" % tid)
self.transactions.append(request)

def getTransaction(self, tid):
""" Returns a transaction matching the referenced tid
Expand All @@ -486,7 +458,7 @@ def delTransaction(self, tid):
:param tid: The transaction to remove
"""
_logger.debug("Deleting transaction %d" % tid)
self.transactions.clear()
self.transactions[:] = []


# --------------------------------------------------------------------------- #
Expand Down

0 comments on commit fd1b8a3

Please sign in to comment.