Last active
July 12, 2018 04:00
-
-
Save njsmith/aa269020e40cc137936805d5d5bbdd91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@attr.s | |
class TrioFuture: | |
_result = attr.ib(default=None) | |
_finished = attr.ib(default=attr.Factory(trio.Event)) | |
def set_result(self, result): | |
assert not self._finished.is_set() | |
self._result = result | |
self._finished.set() | |
async def get(self): | |
await self._finished.wait() | |
return self._result.unwrap() | |
# Sugar | |
def set_value(self, value): | |
self.set_result(trio.hazmat.Value(value)) | |
# Sugar | |
def set_exception(self, exc): | |
self.set_result(trio.hazmat.Error(exc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment