-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graceful shutdown and cleanup #1
Comments
@Michael-F-Bryan I must not be understanding what it is you're saying... I'm attempting to setup a Branch: ttdonovan/connection-send_ch |
I actually implemented a version of this before creating the issue, but wasn't satisfied with it and wanted to see if you had a better solution. I believe the "move out of FnMut" issue is because your Also, the |
Ok I'm really struggling tonight and might just need to take a break - if I remove the
I've posted a message on the user form asking for feedback and maybe someone will have a better solution. |
@Michael-F-Bryan I've made another attempt at setting up the multiple channels and use of threads but instead this time with I'm starting to think now only one thread is need for the "client" connection (currently named |
Just looking at Isn't the API set up so that each bot needs its own connection to the server? |
OK I think I may understand what I need to do now - I created a pseudo example but do not have SC2 running to test it with websockets. What I believe is needed are 3 channels and 2 threads.
For some reason I really struggled wrapping my head around how to set this up - I hope I'm right... |
TODO: look into https://crates.io/crates/tungstenite |
It's kinda annoying how the websockets library has a push-style of doing things (it fires off callbacks when things happen) instead of a pull-style (think iterator of messages) because making sure the listener thread shuts down gracefully when we want it to becomes a pain...
One possible way of doing things is to spin off the listener thread, passing an
Arc<AtomicBool>
(orArc<Mutex<bool>>
) to theClient
which can function as arunning
flag.Then in a
Connection
's shutdown method it'll set therunning
flag tofalse
and wait on the listener thread's handle. For convenience you'd probably also makeConnection
's drop impl callshutdown()
automatically.Meanwhile on the
Client
side you can set a timeout when it first connects. When the timeout fires,Client
will wake up and can check if it's still running, re-scheduling the timeout if it is and closing the connection otherwise.That's all awfully convoluted though, so hopefully you can come up with a less hacky/racy solution 😜
The text was updated successfully, but these errors were encountered: