()
| 78 | } |
| 79 | |
| 80 | func (spool *SessionPool) GetSession() (session Session, err error) { |
| 81 | for { |
| 82 | select { |
| 83 | case spool.sem <- 1: |
| 84 | select { |
| 85 | case session, ok := <-spool.ch: |
| 86 | if ok { |
| 87 | return session, nil |
| 88 | } else { |
| 89 | log.Println("sessionPool has closed") |
| 90 | return session, errPoolClosed |
| 91 | } |
| 92 | default: |
| 93 | config := spool.config |
| 94 | session, err = spool.ConstructSession(config) |
| 95 | if err != nil { |
| 96 | <-spool.sem |
| 97 | } |
| 98 | return session, err |
| 99 | } |
| 100 | case <-time.After(time.Millisecond * time.Duration(spool.waitToGetSessionTimeoutInMs)): |
| 101 | log.Println("get session timeout") |
| 102 | return session, errTimeout |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | func (spool *SessionPool) getTableSession() (ITableSession, error) { |
| 108 | tableSession := PooledTableSession{} |
no test coverage detected