runloop¶
The runloop module contains all functions and constants to use the
Runloop for asynchronous IO programming.
To use the runloop module, add the following import statement to your
project:
import runloop
All functions in the module should be called inside the runloop
module as a prefix like so:
runloop.run(some_async_function())
The following constants are defined:
WAITING= 0SUCCESS= 1TIMEOUT= 2CANCELLED= 3
Functions
|
Start any number of parallel |
|
Pause the execution of the application for any amount of milliseconds. |
|
Returns an awaitable that will return when the condition in the function or lambda passed is |
|
UNDOCUMENTED Behavior is not known; use with caution. |
- runloop.run(*functions)¶
Start any number of parallel
asyncfunctions. This is the function you should use to create programs with a similar structure to Word Blocks.- Parameters:
functions (Awaitable) – A tuple of the functions to run
- Return type:
None
- runloop.sleep_ms(duration)¶
Pause the execution of the application for any amount of milliseconds.
from hub import light_matrix import runloop async def main(): light_matrix.write("Hi!") # Wait for ten seconds await runloop.sleep_ms(10000) light_matrix.write("Are you still here?") runloop.run(main())
- Parameters:
duration (int) – The duration in milliseconds
- Return type:
Awaitable
- runloop.until(function, timeout=0)¶
Returns an awaitable that will return when the condition in the function or lambda passed is
Trueor when it times out.import color_sensor import color from hub import port import runloop def is_color_red(): return color_sensor.color(port.A) is color.RED async def main(): # Wait until Color Sensor sees red await runloop.until(is_color_red) print("Red!") runloop.run(main())
- Parameters:
function (Callable[[], bool]) – A callable with no parameters that returns either
TrueorFalse. Callable is anything that can be called, so adefor alambdatimeout (int) – A timeout for the function in milliseconds. If the callable does not return
Truewithin the timeout, theuntilstill resolves after the timeout. 0 means no timeout, in that case it will not resolve until the callable returnsTrue.
- Return type:
Awaitable
- runloop.wait(unknown)¶
UNDOCUMENTED Behavior is not known; use with caution.
- Parameters:
unknown (Iterator) – Meaning unknown
- Return type:
Awaitable