Removes unnecessary returned func from WaitReady 69/9669/1
authorOndrej Fabry <ofabry@cisco.com>
Thu, 30 Nov 2017 08:08:17 +0000 (09:08 +0100)
committerOndrej Fabry <ofabry@cisco.com>
Thu, 30 Nov 2017 08:08:17 +0000 (09:08 +0100)
Change-Id: I34889c8c79fa8ef7a196f8d067edca7f1cb5ad33
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
adapter/adapter.go
adapter/mock/mock_adapter.go
adapter/vppapiclient/vppapiclient_adapter.go
core/core.go

index d8f29c9..a5b3352 100644 (file)
@@ -31,6 +31,6 @@ type VppAdapter interface {
        // SetMsgCallback sets a callback function that will be called by the adapter whenever a message comes from VPP.
        SetMsgCallback(func(context uint32, msgId uint16, data []byte))
 
-       // WaitReady returns func which waits until adapter is ready.
-       WaitReady() func() error
+       // WaitReady waits until adapter is ready.
+       WaitReady() error
 }
index f85f17d..5407696 100644 (file)
@@ -295,8 +295,8 @@ func (a *VppAdapter) SetMsgCallback(cb func(context uint32, msgID uint16, data [
 }
 
 // WaitReady mocks waiting for VPP
-func (a *VppAdapter) WaitReady() func() error {
-       return func() error { return nil }
+func (a *VppAdapter) WaitReady() error {
+       return nil
 }
 
 // MockReply stores a message to be returned when the next request comes. It is a FIFO queue - multiple replies
index dfdd973..1cdaf72 100644 (file)
@@ -150,33 +150,31 @@ func (a *vppAPIClientAdapter) SetMsgCallback(cb func(context uint32, msgID uint1
        a.callback = cb
 }
 
-// WaitReady returns func which blocks until shared memory
-// for sending bin api calls is present on the file system.
-func (a *vppAPIClientAdapter) WaitReady() func() error {
-       return func() error {
-               watcher, err := fsnotify.NewWatcher()
-               if err != nil {
-                       return err
-               }
-               defer watcher.Close()
+// WaitReady blocks until shared memory for sending
+// binary api calls is present on the file system.
+func (a *vppAPIClientAdapter) WaitReady() error {
+       watcher, err := fsnotify.NewWatcher()
+       if err != nil {
+               return err
+       }
+       defer watcher.Close()
 
-               err = watcher.Add(watchedFolder)
-               if err != nil {
-                       return err
-               }
+       err = watcher.Add(watchedFolder)
+       if err != nil {
+               return err
+       }
 
-               if fileExists(watchedFile) {
-                       return nil
-               }
+       if fileExists(watchedFile) {
+               return nil
+       }
 
-               for {
-                       ev := <-watcher.Events
-                       if ev.Name == watchedFile && (ev.Op&fsnotify.Create) == fsnotify.Create {
-                               break
-                       }
+       for {
+               ev := <-watcher.Events
+               if ev.Name == watchedFile && (ev.Op&fsnotify.Create) == fsnotify.Create {
+                       break
                }
-               return nil
        }
+       return nil
 }
 
 func fileExists(name string) bool {
index c254214..ab0c6bf 100644 (file)
@@ -232,9 +232,8 @@ func (c *Connection) disconnectVPP() {
 // Then it continues with healthCheckLoop.
 func (c *Connection) connectLoop(connChan chan ConnectionEvent) {
        // loop until connected
-       waitForVpp := c.vpp.WaitReady()
        for {
-               waitForVpp()
+               c.vpp.WaitReady()
                if err := c.connectVPP(); err == nil {
                        // signal connected event
                        connChan <- ConnectionEvent{Timestamp: time.Now(), State: Connected}