Skip to content

Commit

Permalink
Make remove_pending_request an instance method
Browse files Browse the repository at this point in the history
  • Loading branch information
sloretz committed Feb 2, 2018
1 parent f60ec40 commit bf87341
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions rclpy/rclpy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ def unblock(future):
raise future.exception()
return future.result()

def remove_pending_request(self, future):
"""
Remove a future from the list of pending requests.
This prevents a future from receiving a request and executing its done callbacks.
:param future: a future returned from :meth:`call_async`
:type future: rclpy.task.Future
"""
for seq, req_future in self._pending_requests.items():
if future == req_future:
try:
del self._pending_requests[seq]
except KeyError:
pass
break

def call_async(self, req):
"""
Make a service request and asyncronously get the result.
Expand All @@ -70,11 +86,7 @@ def call_async(self, req):
future = Future()
self._pending_requests[sequence_number] = future

def remove_pending_request(future):
nonlocal self, sequence_number
del self._pending_requests[sequence_number]

future.add_done_callback(remove_pending_request)
future.add_done_callback(self.remove_pending_request)

return future

Expand Down

0 comments on commit bf87341

Please sign in to comment.