You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i have some code setting up a websocket-like client that is async that i then want to use inside a coroutine. my reason for this is setting up a client that can be heavy. so i'd like to set it up once and then be able to use it in the coroutine. my thought was to check if the resource is Some. if not, it exits the coroutine. otherwise it continue to my business logic. however, the coroutine only runs once, at the beginning of the program. it makes sense to some extent that it wouldn't work the way i was thinking, but i'm looking for a pattern that will work for me. would using an enum as the messages on the coroutine's channel be the suggested way to pass in some of client?
an example of what i'd like to do.
let keys = use_signal(|| Keys::generate());let client = use_resource(move || asyncmove{let client = Client::new(keys());
client.connect().await;
client
};let _:Coroutine<()> = use_coroutine(|_| asyncmove{debug!("looking for zaps");letSome(client) = client()else{
return;};// do some other work with looping};
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
i have some code setting up a websocket-like client that is
async
that i then want to use inside a coroutine. my reason for this is setting up a client that can be heavy. so i'd like to set it up once and then be able to use it in the coroutine. my thought was to check if the resource isSome
. if not, it exits the coroutine. otherwise it continue to my business logic. however, the coroutine only runs once, at the beginning of the program. it makes sense to some extent that it wouldn't work the way i was thinking, but i'm looking for a pattern that will work for me. would using an enum as the messages on the coroutine's channel be the suggested way to pass in some of client?an example of what i'd like to do.
Beta Was this translation helpful? Give feedback.
All reactions