Yielding Updates
A regular event handler will send a StateUpdate
when it has finished running. This works fine for basic event, but sometimes we need more complex logic. To update the UI multiple times in an event handler, we can yield
when we want to send an update.
To do so, we can use the Python keyword yield
. For every yield inside the function, a StateUpdate
will be sent to the frontend with the changes up to this point in the execution of the event handler.
This example below shows how to yield 100 updates to the UI.
0
Here is another example of yielding multiple updates with a loading icon.
Yielding Other Events
Events can also yield other events. This is useful when you want to chain events together. To do this, you can yield the event handler function itself.