Replies: 1 comment 1 reply
-
afaik there is currently no simpler approach. I wanted to simplify the connection state here: #2671 With #2771 we could even extend this idea to a one-task-per-user decorator. cc @abulvenz |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'd like to run some tasks in the background that can periodically push updates to the user, but I'm not sure how best to handle the lifetime of the task.
To give a bit more context, here is a minimal example of the sort of thing I'm trying to do.
@masenf Gave a nice suggestion a while ago in #1857 that was similar. This is the relevant part:
Where something similar could be done for
on_connect
.This is close to what I am looking for in that the events trigger at client connect/disconnect. I'm just not sure how I can start a background task from the
on_connect
equivalent. In my case, I'd use theon_disconnect
to sendSTOP
to "some_client_specific_channel".There is also this #1970, which is also similar in nature. In fact, I am currently using a recommendation there to use
rx.moment
to periodically start the long running background task with a timeout that will prevent it running forever if the user closes the tab.In this case, to prevent two tasks running at once per user, I just send a
STOP
to the channel immediately before beginning to listen again. Overall, this is a bit messy though, and I'd prefer to just use the actual connect/disconnect events directly.Or is there a much simpler approach I am overlooking entirely?
Beta Was this translation helpful? Give feedback.
All reactions