You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ORPA-pyOpenRPA/Resources/WPy64-3720/python-3.7.2.amd64/Lib/site-packages/prompt_toolkit/eventloop/event.py

43 lines
791 B

"""
Asyncronous event implementation.
"""
from __future__ import unicode_literals
from .future import Future
__all__ = [
'Event'
]
class Event(object):
"""
Like `asyncio.event`.
The state is intially false.
"""
def __init__(self):
self._state = False
self._waiting_futures = []
def is_set(self):
return self._state
def clear(self):
self._state = False
def set(self):
self._state = True
futures = self._waiting_futures
self._waiting_futures = []
for f in futures:
f.set_result(None)
def wait(self):
if self._state:
return Future.succeed(None)
else:
f = Future()
self._waiting_futures.append(f)
return f