summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimport/session.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-20 01:29:13 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-20 01:29:13 (GMT)
commit8fc2a9c93d566feae576c1421b3c64dabc4b4976 (patch)
tree2fcef9fdc3fa620d44989985b1878b807dbe456f /src/helsinki.at/rhimport/session.go
parent9f860e6f74791e103aed25a006dee55d7b3822b5 (diff)
improved type safety
Diffstat (limited to 'src/helsinki.at/rhimport/session.go')
-rw-r--r--src/helsinki.at/rhimport/session.go43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/helsinki.at/rhimport/session.go b/src/helsinki.at/rhimport/session.go
index 219c233..718d13e 100644
--- a/src/helsinki.at/rhimport/session.go
+++ b/src/helsinki.at/rhimport/session.go
@@ -61,7 +61,7 @@ type sessionRunResponse struct {
type sessionRunRequest struct {
user string
id string
- response chan sessionRunResponse
+ response chan<- sessionRunResponse
}
type sessionAddProgressHandlerResponse struct {
@@ -72,8 +72,8 @@ type sessionAddProgressHandlerRequest struct {
user string
id string
userdata interface{}
- handler chan ProgressData
- response chan sessionAddProgressHandlerResponse
+ handler chan<- ProgressData
+ response chan<- sessionAddProgressHandlerResponse
}
type sessionAddDoneHandlerResponse struct {
@@ -84,8 +84,8 @@ type sessionAddDoneHandlerRequest struct {
user string
id string
userdata interface{}
- handler chan ImportResult
- response chan sessionAddDoneHandlerResponse
+ handler chan<- ImportResult
+ response chan<- sessionAddDoneHandlerResponse
}
type sessionRemoveResponse struct {
@@ -125,12 +125,13 @@ func (self *SessionStore) newSession(ctx ImportContext) (resp newSessionResponse
}
func (self *SessionStore) NewSession(ctx ImportContext) (string, error) {
+ res_ch := make(chan newSessionResponse)
req := newSessionRequest{}
req.ctx = ctx
- req.response = make(chan newSessionResponse)
+ req.response = res_ch
self.newChan <- req
- res := <-req.response
+ res := <-res_ch
if res.err != nil {
return "", res.err
}
@@ -147,17 +148,18 @@ func (self *SessionStore) run(user, id string) (resp sessionRunResponse) {
}
func (self *SessionStore) Run(user, id string) error {
+ res_ch := make(chan sessionRunResponse)
req := sessionRunRequest{}
req.user = user
req.id = id
- req.response = make(chan sessionRunResponse)
+ req.response = res_ch
self.runChan <- req
- res := <-req.response
+ res := <-res_ch
return res.err
}
-func (self *SessionStore) addProgressHandler(user, id string, userdata interface{}, handler chan ProgressData) (resp sessionAddProgressHandlerResponse) {
+func (self *SessionStore) addProgressHandler(user, id string, userdata interface{}, handler chan<- ProgressData) (resp sessionAddProgressHandlerResponse) {
if _, exists := self.store[user][id]; exists {
rhdl.Printf("SessionStore: adding progress handler to '%s/%s'", user, id)
} else {
@@ -166,20 +168,21 @@ func (self *SessionStore) addProgressHandler(user, id string, userdata interface
return
}
-func (self *SessionStore) AddProgressHandler(user, id string, userdata interface{}, handler chan ProgressData) error {
+func (self *SessionStore) AddProgressHandler(user, id string, userdata interface{}, handler chan<- ProgressData) error {
+ res_ch := make(chan sessionAddProgressHandlerResponse)
req := sessionAddProgressHandlerRequest{}
req.user = user
req.id = id
req.userdata = userdata
req.handler = handler
- req.response = make(chan sessionAddProgressHandlerResponse)
+ req.response = res_ch
self.addProgressChan <- req
- res := <-req.response
+ res := <-res_ch
return res.err
}
-func (self *SessionStore) addDoneHandler(user, id string, userdata interface{}, handler chan ImportResult) (resp sessionAddDoneHandlerResponse) {
+func (self *SessionStore) addDoneHandler(user, id string, userdata interface{}, handler chan<- ImportResult) (resp sessionAddDoneHandlerResponse) {
if _, exists := self.store[user][id]; exists {
rhdl.Printf("SessionStore: adding done handler to '%s/%s'", user, id)
} else {
@@ -188,16 +191,17 @@ func (self *SessionStore) addDoneHandler(user, id string, userdata interface{},
return
}
-func (self *SessionStore) AddDoneHandler(user, id string, userdata interface{}, handler chan ImportResult) error {
+func (self *SessionStore) AddDoneHandler(user, id string, userdata interface{}, handler chan<- ImportResult) error {
+ res_ch := make(chan sessionAddDoneHandlerResponse)
req := sessionAddDoneHandlerRequest{}
req.user = user
req.id = id
req.userdata = userdata
req.handler = handler
- req.response = make(chan sessionAddDoneHandlerResponse)
+ req.response = res_ch
self.addDoneChan <- req
- res := <-req.response
+ res := <-res_ch
return res.err
}
@@ -218,13 +222,14 @@ func (self *SessionStore) remove(user, id string) (resp sessionRemoveResponse) {
}
func (self *SessionStore) Remove(user, id string) error {
+ res_ch := make(chan sessionRemoveResponse)
req := sessionRemoveRequest{}
req.user = user
req.id = id
- req.response = make(chan sessionRemoveResponse)
+ req.response = res_ch
self.removeChan <- req
- res := <-req.response
+ res := <-res_ch
return res.err
}