MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / async_wait_until

Function async_wait_until

test/asynchronous/utils.py:59–85  ·  view source on GitHub ↗

Wait up to 10 seconds (by default) for predicate to be true. E.g.: wait_until(lambda: client.primary == ('a', 1), 'connect to the primary') If the lambda-expression isn't true after 10 seconds, we raise AssertionError("Didn't ever connect to the primary").

(predicate, success_description, timeout=10)

Source from the content-addressed store, hash-verified

57
58
59async def async_wait_until(predicate, success_description, timeout=10):
60 """Wait up to 10 seconds (by default) for predicate to be true.
61
62 E.g.:
63
64 wait_until(lambda: client.primary == ('a', 1),
65 'connect to the primary')
66
67 If the lambda-expression isn't true after 10 seconds, we raise
68 AssertionError("Didn't ever connect to the primary").
69
70 Returns the predicate's first true value.
71 """
72 start = time.time()
73 interval = min(float(timeout) / 100, 0.1)
74 while True:
75 if iscoroutinefunction(predicate):
76 retval = await predicate()
77 else:
78 retval = predicate()
79 if retval:
80 return retval
81
82 if time.time() - start > timeout:
83 raise AssertionError("Didn't ever %s" % success_description)
84
85 await asyncio.sleep(interval)
86
87
88async def async_is_mongos(client):

Calls 2

timeMethod · 0.80
predicateFunction · 0.70