From b790c538386499ca531bae9ecc331fc1f1cb15b2 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sat, 11 Feb 2017 13:42:16 +0300 Subject: [PATCH] initialize server channel earlier for config file Mentioned in #36. --- app.go | 14 +------------- client.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app.go b/app.go index 8ff6f12..c61a135 100644 --- a/app.go +++ b/app.go @@ -3,7 +3,6 @@ package main import ( "fmt" "log" - "net" "os" "os/exec" "strconv" @@ -55,20 +54,9 @@ func waitKey() error { // This is the main event loop of the application. There are two channels to // read expressions from client and server. Reading and evaluation are done on // separate goroutines. -func (app *app) handleInp() { +func (app *app) handleInp(serverChan <-chan expr) { clientChan := app.ui.readExpr() - var serverChan <-chan expr - - c, err := net.Dial("unix", gSocketPath) - if err != nil { - msg := fmt.Sprintf("connecting server: %s", err) - app.ui.message = msg - log.Printf(msg) - } else { - serverChan = readExpr(c) - } - for { select { case <-app.quit: diff --git a/client.go b/client.go index 4e4c249..af0a66b 100644 --- a/client.go +++ b/client.go @@ -31,6 +31,17 @@ func client() { app.ui.loadFile(app.nav) + var serverChan <-chan expr + + c, err := net.Dial("unix", gSocketPath) + if err != nil { + msg := fmt.Sprintf("connecting server: %s", err) + app.ui.message = msg + log.Printf(msg) + } else { + serverChan = readExpr(c) + } + if err := app.nav.sync(); err != nil { msg := fmt.Sprintf("sync: %s", err) app.ui.message = msg @@ -61,7 +72,7 @@ func client() { app.ui.draw(app.nav) - app.handleInp() + app.handleInp(serverChan) } func readExpr(c net.Conn) <-chan expr {