eugene
eugene3mo ago

Terminate a while loop with switch and state

I'm trying to implement an app and a crucial part of it composed of something like below,
get_state, set_state = mo.state(False)

def wait_for_switch() -> bool:
while True:
if get_state():
return True

switch = mo.ui.switch(on_change=set_state)
get_state, set_state = mo.state(False)

def wait_for_switch() -> bool:
while True:
if get_state():
return True

switch = mo.ui.switch(on_change=set_state)
then calling
wait_for_switch()
wait_for_switch()
But when switching, the loop continues Is there a way to terminate this while loop with switch?
2 Replies
Myles Scolnick
Myles Scolnick3mo ago
could you try mo.ui.run_button? or mo.stop() ? those may be able to help you achieve the same thing, but use some lower-level internal APIs so to no create an infinite loop
eugene
eugeneOP3mo ago
I think run_button can help