diff options
Diffstat (limited to 'session.go')
-rw-r--r-- | session.go | 38 |
1 files changed, 19 insertions, 19 deletions
@@ -39,7 +39,7 @@ const ( ) type Session struct { - ctx ImportContext + ctx Context state int removeFunc func() done chan bool @@ -47,7 +47,7 @@ type Session struct { timer *time.Timer cancelIntChan chan bool progressIntChan chan ProgressData - doneIntChan chan ImportResult + doneIntChan chan Result runChan chan time.Duration cancelChan chan bool addProgressChan chan sessionAddProgressHandlerRequest @@ -57,12 +57,12 @@ type Session struct { } type SessionProgressCB struct { - cb ImportProgressCB + cb ProgressCB userdata interface{} } type SessionDoneCB struct { - cb ImportDoneCB + cb DoneCB userdata interface{} } @@ -78,7 +78,7 @@ type sessionAddProgressHandlerResponse struct { type sessionAddProgressHandlerRequest struct { userdata interface{} - callback ImportProgressCB + callback ProgressCB response chan<- sessionAddProgressHandlerResponse } @@ -88,7 +88,7 @@ type sessionAddDoneHandlerResponse struct { type sessionAddDoneHandlerRequest struct { userdata interface{} - callback ImportDoneCB + callback DoneCB response chan<- sessionAddDoneHandlerResponse } @@ -98,14 +98,14 @@ func sessionProgressCallback(step int, stepName string, progress float64, userda return true } -func sessionImportRun(ctx ImportContext, done chan<- ImportResult) { +func sessionRun(ctx Context, done chan<- Result) { if err := ctx.SanityCheck(); err != nil { - done <- ImportResult{http.StatusBadRequest, err.Error(), 0, 0} + done <- Result{http.StatusBadRequest, err.Error(), 0, 0} return } if res, err := FetchFile(&ctx); err != nil { - done <- ImportResult{http.StatusInternalServerError, err.Error(), 0, 0} + done <- Result{http.StatusInternalServerError, err.Error(), 0, 0} return } else if res.ResponseCode != http.StatusOK { done <- *res @@ -113,7 +113,7 @@ func sessionImportRun(ctx ImportContext, done chan<- ImportResult) { } if res, err := ImportFile(&ctx); err != nil { - done <- ImportResult{http.StatusInternalServerError, err.Error(), 0, 0} + done <- Result{http.StatusInternalServerError, err.Error(), 0, 0} return } else { done <- *res @@ -125,7 +125,7 @@ func (self *Session) run(timeout time.Duration) { self.ctx.ProgressCallBack = sessionProgressCallback self.ctx.ProgressCallBackData = (chan<- ProgressData)(self.progressIntChan) self.ctx.Cancel = self.cancelIntChan - go sessionImportRun(self.ctx, self.doneIntChan) + go sessionRun(self.ctx, self.doneIntChan) self.state = SESSION_RUNNING self.timer.Reset(timeout) return @@ -140,7 +140,7 @@ func (self *Session) cancel() { self.state = SESSION_CANCELED } -func (self *Session) addProgressHandler(userdata interface{}, cb ImportProgressCB) (resp sessionAddProgressHandlerResponse) { +func (self *Session) addProgressHandler(userdata interface{}, cb ProgressCB) (resp sessionAddProgressHandlerResponse) { if self.state != SESSION_NEW && self.state != SESSION_RUNNING { resp.err = fmt.Errorf("session is already done/canceled") } @@ -148,7 +148,7 @@ func (self *Session) addProgressHandler(userdata interface{}, cb ImportProgressC return } -func (self *Session) addDoneHandler(userdata interface{}, cb ImportDoneCB) (resp sessionAddDoneHandlerResponse) { +func (self *Session) addDoneHandler(userdata interface{}, cb DoneCB) (resp sessionAddDoneHandlerResponse) { if self.state != SESSION_NEW && self.state != SESSION_RUNNING { resp.err = fmt.Errorf("session is already done/canceled") } @@ -166,7 +166,7 @@ func (self *Session) callProgressHandler(p *ProgressData) { } } -func (self *Session) callDoneHandler(r *ImportResult) { +func (self *Session) callDoneHandler(r *Result) { for _, cb := range self.doneCBs { if cb.cb != nil { if keep := cb.cb(*r, cb.userdata); !keep { @@ -190,7 +190,7 @@ func (self *Session) dispatchRequests() { self.cancel() } self.state = SESSION_TIMEOUT - r := &ImportResult{500, "session timed out", 0, 0} + r := &Result{500, "session timed out", 0, 0} self.callDoneHandler(r) if self.removeFunc != nil { self.removeFunc() @@ -246,7 +246,7 @@ func (self *SessionChan) Cancel() { } } -func (self *SessionChan) AddProgressHandler(userdata interface{}, cb ImportProgressCB) error { +func (self *SessionChan) AddProgressHandler(userdata interface{}, cb ProgressCB) error { resCh := make(chan sessionAddProgressHandlerResponse) req := sessionAddProgressHandlerRequest{} req.userdata = userdata @@ -262,7 +262,7 @@ func (self *SessionChan) AddProgressHandler(userdata interface{}, cb ImportProgr return res.err } -func (self *SessionChan) AddDoneHandler(userdata interface{}, cb ImportDoneCB) error { +func (self *SessionChan) AddDoneHandler(userdata interface{}, cb DoneCB) error { resCh := make(chan sessionAddDoneHandlerResponse) req := sessionAddDoneHandlerRequest{} req.userdata = userdata @@ -309,7 +309,7 @@ func (self *Session) cleanup() { rhdl.Printf("session is now cleaned up") } -func newSession(ctx *ImportContext, removeFunc func()) (session *Session) { +func newSession(ctx *Context, removeFunc func()) (session *Session) { session = new(Session) session.state = SESSION_NEW session.removeFunc = removeFunc @@ -318,7 +318,7 @@ func newSession(ctx *ImportContext, removeFunc func()) (session *Session) { session.timer = time.NewTimer(10 * time.Second) session.cancelIntChan = make(chan bool, 1) session.progressIntChan = make(chan ProgressData, 10) - session.doneIntChan = make(chan ImportResult, 1) + session.doneIntChan = make(chan Result, 1) session.runChan = make(chan time.Duration, 1) session.cancelChan = make(chan bool, 1) session.addProgressChan = make(chan sessionAddProgressHandlerRequest, 10) |