Download this file
| 1 | package sheets |
| 2 | |
| 3 | import ( |
| 4 | "sync" |
| 5 | |
| 6 | "amadan.net/rastrillo/rastrillo/auth" |
| 7 | ) |
| 8 | |
| 9 | // signinQueues is every queue NewAuth built, by the plugin it feeds, so |
| 10 | // CloseSigninMail can stop one and DrainSigninMail all of them. |
| 11 | var ( |
| 12 | signinQueuesMu sync.Mutex |
| 13 | signinQueues = map[*auth.Auth]*mailQueue{} |
| 14 | ) |
| 15 | |
| 16 | // CloseSigninMail stops the sign-in mail queue behind x, sending what |
| 17 | // is still in it within the queue's deadline. Tests close every plugin |
| 18 | // they build with it. |
| 19 | func CloseSigninMail(x *auth.Auth) { |
| 20 | signinQueuesMu.Lock() |
| 21 | q := signinQueues[x] |
| 22 | delete(signinQueues, x) |
| 23 | signinQueuesMu.Unlock() |
| 24 | if q != nil { |
| 25 | q.close() |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // DrainSigninMail stops every sign-in mail queue and sends what is |
| 30 | // still in them. main calls it once Serve returns. |
| 31 | func DrainSigninMail() { |
| 32 | signinQueuesMu.Lock() |
| 33 | qs := signinQueues |
| 34 | signinQueues = map[*auth.Auth]*mailQueue{} |
| 35 | signinQueuesMu.Unlock() |
| 36 | for _, q := range qs { |
| 37 | q.close() |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | // queueAttacher is a test mailer that wants to wait for the queue in |
| 42 | // front of it before it is read (begin_test.go's recorder). |
| 43 | type queueAttacher interface{ attachQueue(wait func()) } |
| 44 | |