Skip to content

Instantly share code, notes, and snippets.

@boxofrox
Created March 23, 2017 16:29
Show Gist options
  • Save boxofrox/65766802970f33cdedc72cfb7f2917de to your computer and use it in GitHub Desktop.
Save boxofrox/65766802970f33cdedc72cfb7f2917de to your computer and use it in GitHub Desktop.
Match alternative: squashed, uses fewer lines, not necessarily easier to read.
pub fn start_event_loop_cb<F, G>(&mut self,
notify_handler: Option<F>,
request_handler: Option<G>)
where F: FnMut(&str, Vec<Value>) + Send + 'static,
G: FnMut(&str, Vec<Value>) -> Result<Value, Value> + Send + 'static
{
let queue = self.queue.clone();
let reader = self.reader.take().unwrap();
let writer = self.writer.clone();
self.dispatch_guard = match (notify_handler, request_handler) {
(None, None) => {
let (f, g) = (default_notify_handler, default_request_handler);
Some(Self::dispatch_thread(queue, reader, writer, f, g))
}
(Some(f), None) => {
let g = default_request_handler;
Some(Self::dispatch_thread(queue, reader, writer, f, g))
}
(None, Some(g)) => {
let f = default_notify_handler;
Some(Self::dispatch_thread(queue, reader, writer, f, g))
}
(Some(f), Some(g)) => Some(Self::dispatch_thread(queue, reader, writer, f, g)),
};
self.event_loop_started = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment