(ctx context.Context)
| 718 | } |
| 719 | |
| 720 | func (mc *mysqlConn) watchCancel(ctx context.Context) error { |
| 721 | if mc.watching { |
| 722 | // Reach here if canceled, |
| 723 | // so the connection is already invalid |
| 724 | mc.cleanup() |
| 725 | return nil |
| 726 | } |
| 727 | // When ctx is already cancelled, don't watch it. |
| 728 | if err := ctx.Err(); err != nil { |
| 729 | return err |
| 730 | } |
| 731 | // When ctx is not cancellable, don't watch it. |
| 732 | if ctx.Done() == nil { |
| 733 | return nil |
| 734 | } |
| 735 | // When watcher is not alive, can't watch it. |
| 736 | if mc.watcher == nil { |
| 737 | return nil |
| 738 | } |
| 739 | |
| 740 | mc.watching = true |
| 741 | mc.watcher <- ctx |
| 742 | return nil |
| 743 | } |
| 744 | |
| 745 | func (mc *mysqlConn) startWatcher() { |
| 746 | watcher := make(chan context.Context, 1) |
no test coverage detected