summaryrefslogtreecommitdiff
path: root/session.go
diff options
context:
space:
mode:
Diffstat (limited to 'session.go')
-rw-r--r--session.go43
1 files changed, 24 insertions, 19 deletions
diff --git a/session.go b/session.go
index 219c233..718d13e 100644
--- a/session.go
+++ b/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
}