Acquire database lock and release it when not needed anymore. Should be run in a goroutine!
()
| 106 | // |
| 107 | // Should be run in a goroutine! |
| 108 | func acquireDatabase() { |
| 109 | clients := 0 |
| 110 | for request := range dbRequests { |
| 111 | var err error |
| 112 | |
| 113 | switch request.kind { |
| 114 | case acquiredb: |
| 115 | if clients == 0 { |
| 116 | err = context.ReOpenDatabase() |
| 117 | } |
| 118 | |
| 119 | request.err <- err |
| 120 | |
| 121 | if err == nil { |
| 122 | clients++ |
| 123 | } |
| 124 | case releasedb: |
| 125 | clients-- |
| 126 | if clients == 0 { |
| 127 | err = context.CloseDatabase() |
| 128 | } else { |
| 129 | err = nil |
| 130 | } |
| 131 | |
| 132 | request.err <- err |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // Should be called before database access is needed in any api call. |
| 138 | // Happens per default for each api call. It is important that you run |
no test coverage detected