-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnhancedFuture.py
More file actions
26 lines (22 loc) · 1.16 KB
/
EnhancedFuture.py
File metadata and controls
26 lines (22 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import asyncio
import time
from typing import Any, Optional
#########################################################################################################
#########################################################################################################
##### EnhancedFuture (Public)
#### - This class is used to extend the asyncio.Future class to include additional data (cost, elasped_time) <- Not Needed
#########################################################################################################
#########################################################################################################
class EnhancedFuture(asyncio.Future):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.cost: Optional[float] = None
self.start_time: float = time.time()
self.elasped_time: float = -1
def set_cost(self, cost: float) -> None:
self.cost = cost
def get_cost(self) -> Optional[float]:
return self.cost
def set_result(self, result: Any) -> None:
self.elapsed_time = time.time() - self.start_time
super().set_result(result)