Skip to content

Commit 03c3dd2

Browse files
committed
FutureSelector: More generic interface to concurrent.futures.Future
1 parent 0edc7c3 commit 03c3dd2

1 file changed

Lines changed: 11 additions & 26 deletions

File tree

executorlib/standalone/select.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@
44

55
class FutureSelector(Future):
66
def __init__(self, future: Future, selector: int | str):
7-
super().__init__()
87
self._future = future
98
self._selector = selector
9+
super().__init__()
1010

11-
def cancel(self) -> bool:
12-
return self._future.cancel()
13-
14-
def cancelled(self) -> bool:
15-
return self._future.cancelled()
16-
17-
def running(self) -> bool:
18-
return self._future.running()
19-
20-
def done(self) -> bool:
21-
return self._future.done()
11+
def __getattr__(self, attr: str):
12+
if attr in ["_future", "_selector"]:
13+
return super().__getattribute__(attr)
14+
else:
15+
return getattr(self._future, attr)
2216

23-
def add_done_callback(self, fn) -> None:
24-
return self._future.add_done_callback(fn=fn)
17+
def __setattr__(self, name: str, value: Any):
18+
if name in ["_future", "_selector"]:
19+
super().__setattr__(name, value)
20+
else:
21+
setattr(self._future, name, value)
2522

2623
def result(self, timeout: Optional[float] = None) -> Any:
2724
result = self._future.result(timeout=timeout)
@@ -30,18 +27,6 @@ def result(self, timeout: Optional[float] = None) -> Any:
3027
else:
3128
return None
3229

33-
def exception(self, timeout: Optional[float] = None) -> Optional[BaseException]:
34-
return self._future.exception(timeout=timeout)
35-
36-
def set_running_or_notify_cancel(self) -> bool:
37-
return self._future.set_running_or_notify_cancel()
38-
39-
def set_result(self, result: Any) -> None:
40-
return self._future.set_result(result=result)
41-
42-
def set_exception(self, exception: Optional[BaseException]) -> None:
43-
return self._future.set_exception(exception=exception)
44-
4530

4631
def split_future(future: Future, n: int) -> list[FutureSelector]:
4732
"""

0 commit comments

Comments
 (0)