Skip to content

How to implement continues sampling in a Rio GUI #185

Answered by mad-moo
Nachsh asked this question in Q&A
Discussion options

You must be logged in to vote

Easy! Use the periodic event. It will continuously fire until the component is garbage collected

class MyRoot(rio.Component):
    counter: int = 0


    @rio.event.periodic(2)
    async def _on_periodic(self) -> None:
        self.counter += 1
        await self.force_refresh()

    def build(self) -> rio.Component:
        return rio.Text(
            f"Counter: {self.counter}",
            justify="center",
        )

In general, threading is rarely needed, especially in modern codebases. All of Rio supports asynchrony, so asyncio tasks are almost always preferred over threads.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Nachshon-d
Comment options

Answer selected by Nachsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants