A collection of results. Arguments: results (Sequence[AsyncResult]): List of result instances.
| 549 | |
| 550 | @Thenable.register |
| 551 | class ResultSet(ResultBase): |
| 552 | """A collection of results. |
| 553 | |
| 554 | Arguments: |
| 555 | results (Sequence[AsyncResult]): List of result instances. |
| 556 | """ |
| 557 | |
| 558 | _app = None |
| 559 | |
| 560 | #: List of results in in the set. |
| 561 | results = None |
| 562 | |
| 563 | def __init__(self, results, app=None, ready_barrier=None, **kwargs): |
| 564 | self._app = app |
| 565 | self.results = results |
| 566 | self.on_ready = promise(args=(proxy(self),)) |
| 567 | self._on_full = ready_barrier or barrier(results) |
| 568 | if self._on_full: |
| 569 | self._on_full.then(promise(self._on_ready, weak=True)) |
| 570 | |
| 571 | def add(self, result): |
| 572 | """Add :class:`AsyncResult` as a new member of the set. |
| 573 | |
| 574 | Does nothing if the result is already a member. |
| 575 | """ |
| 576 | if result not in self.results: |
| 577 | self.results.append(result) |
| 578 | if self._on_full: |
| 579 | self._on_full.add(result) |
| 580 | |
| 581 | def _on_ready(self): |
| 582 | if self.backend.is_async: |
| 583 | self.on_ready() |
| 584 | |
| 585 | def remove(self, result): |
| 586 | """Remove result from the set; it must be a member. |
| 587 | |
| 588 | Raises: |
| 589 | KeyError: if the result isn't a member. |
| 590 | """ |
| 591 | if isinstance(result, str): |
| 592 | result = self.app.AsyncResult(result) |
| 593 | try: |
| 594 | self.results.remove(result) |
| 595 | except ValueError: |
| 596 | raise KeyError(result) |
| 597 | |
| 598 | def discard(self, result): |
| 599 | """Remove result from the set if it is a member. |
| 600 | |
| 601 | Does nothing if it's not a member. |
| 602 | """ |
| 603 | try: |
| 604 | self.remove(result) |
| 605 | except KeyError: |
| 606 | pass |
| 607 | |
| 608 | def update(self, results): |
no outgoing calls