Replies: 1 comment 6 replies
-
Why not just simply:
You can try to manage the async task, but why? Why not allow the user to do this - they may start a task, which starts a task, which calls an API, who's response is entered into a queue, which is consumed by .... .... and finally calls something that wants to update the UI state. If you want the ability for reflex to kill the task:
|
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The next release (0.2.8) will include support for background tasks to allow long running jobs to interact with the state without blocking UI interactions.
A background task is a special event handler which runs concurrently with other event handlers.
To avoid two event handlers modifying the state at the same time, a background task may only set state vars in a context block. Within an
async with self
context block an exclusive lock is acquired on the state, preventing other event handlers and background tasks from also modifying the state. After exiting the context, any updates are sent to the frontend, similar to usingyield
in a normal event handler.Your feedback, suggestions, and comments are welcome 🙏.
Want to test it?
pip install git+https://github.com/reflex-dev/reflex@masenf/oob-state-update
Beta Was this translation helpful? Give feedback.
All reactions