-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpcserver: Convert ws client lifecycle to context.
This modifies the lifecycle of websocket clients to use the expected pattern for running subsystems based on contexts. In particular, this replaces the Start and WaitForShutdown methods with a single method named Run and arranges for it to block until the provided context is cancelled. This is more flexible for the caller since it can easily turn blocking code into async code while the reverse is not true. The new Run method waits for all goroutines that it starts to shutdown before returning to help ensure an orderly shutdown. Since there are exported methods that send messages to the output and notification handler goroutines via channels and those goroutines are stopped during the shutdown process, all sends select across both the channels in question as well as a quit channel which is closed when the context it cancelled. This ensures callers can't end up blocking on send to a goroutine that is no longer running without needing additional mutexes.
- Loading branch information
Showing
1 changed file
with
68 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters