| 506 | |
| 507 | |
| 508 | class ExecutorFuture: |
| 509 | def __init__(self, future): |
| 510 | """A future returned from the executor |
| 511 | |
| 512 | Currently, it is just a wrapper around a concurrent.futures.Future. |
| 513 | However, this can eventually grow to implement the needed functionality |
| 514 | of concurrent.futures.Future if we move off of the library and not |
| 515 | affect the rest of the codebase. |
| 516 | |
| 517 | :type future: concurrent.futures.Future |
| 518 | :param future: The underlying future |
| 519 | """ |
| 520 | self._future = future |
| 521 | |
| 522 | def result(self): |
| 523 | return self._future.result() |
| 524 | |
| 525 | def add_done_callback(self, fn): |
| 526 | """Adds a callback to be completed once future is done |
| 527 | |
| 528 | :param fn: A callable that takes no arguments. Note that is different |
| 529 | than concurrent.futures.Future.add_done_callback that requires |
| 530 | a single argument for the future. |
| 531 | """ |
| 532 | |
| 533 | # The done callback for concurrent.futures.Future will always pass a |
| 534 | # the future in as the only argument. So we need to create the |
| 535 | # proper signature wrapper that will invoke the callback provided. |
| 536 | def done_callback(future_passed_to_callback): |
| 537 | return fn() |
| 538 | |
| 539 | self._future.add_done_callback(done_callback) |
| 540 | |
| 541 | def done(self): |
| 542 | return self._future.done() |
| 543 | |
| 544 | |
| 545 | class BaseExecutor: |
no outgoing calls