Comments (1)
uuu thanks i see the race, that for {} it's not need, we can let main for to handle reconnection
gracias
El 26 de marzo de 2015 4:42:39 GMT-05:00, markose [email protected] escribió:
Hello,
thank you for the AMI Adapter, it's great work.
Though it seems that there are two small issues with the reconnect
machanism you provide. Please have a look at the following code
snippets. I commented two lines with '!!!!!'it seems that your reconnect does not work properly as there is a race
condition in your example code:########################################
func (client *AMIClient) Reconnect() error {
client.conn.Close()
reconnect, err := Dial(client.address)if err != nil {
//client.NetError <- err <--- !!!!!! Do not pass the error to the
channel, because it blocks
return err
}//new connection
client.conn = reconnect.conn
client.connRaw = reconnect.connRaw
client.waitNewConnection <- struct{}{}if err := client.Login(client.amiUser, client.amiPass); err != nil {
return err
}return nil
}
########################################//install manager
go func() {
for {
select {
//handle network errors
case err := <-ami.NetError:
log.Println("Network Error:", err)
//try new connection every second
for {
<-time.After(time.Second)
if err := ami.Reconnect(); err == nil {
//call start actions
if _, err := ami.Action("Events", gami.Params{"EventMask":
"on"}); err != nil { // <--- !!!!!! This should break if 'err == nil'
--> Seems to be a typo
break
}
}
}case err := <-ami.Error: log.Println("error:", err) //wait events and process case ev := <-ami.Events: log.Println("Event Detect: %v", *ev) //if want type of events log.Println("EventType:", event.New(ev)) } }
}()
Regards,
Marko
Reply to this email directly or view it on GitHub:
#1
from gami.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gami.