From 37d525bcb819041ec38b04d8352b95a3f6845901 Mon Sep 17 00:00:00 2001 From: gusaul Date: Tue, 2 Apr 2019 09:45:50 +0700 Subject: [PATCH] add timeout cancelation connection --- core/resource.go | 25 ++++++++++++++++++------- index/js/style.js | 3 ++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/core/resource.go b/core/resource.go index ca01ffb..c121b48 100644 --- a/core/resource.go +++ b/core/resource.go @@ -165,13 +165,24 @@ func (r *Resource) Invoke(ctx context.Context, symbol string, in io.Reader) (str // Close - to close all resources that was opened before func (r *Resource) Close() { - if r.refClient != nil { - r.refClient.Reset() - r.refClient = nil - } - if r.clientConn != nil { - r.clientConn.Close() - r.clientConn = nil + done := make(chan int) + go func() { + if r.refClient != nil { + r.refClient.Reset() + r.refClient = nil + } + if r.clientConn != nil { + r.clientConn.Close() + r.clientConn = nil + } + done <- 1 + }() + + select { + case <-done: + return + case <-time.After(3 * time.Second): + return } } diff --git a/index/js/style.js b/index/js/style.js index c758e08..e9363e6 100644 --- a/index/js/style.js +++ b/index/js/style.js @@ -248,7 +248,8 @@ function refreshConnCount() { function refreshToolTip() { $(function () { - $('[data-toggle="tooltip"]').tooltip() + $('[data-toggle="tooltip"]').tooltip('dispose'); + $('[data-toggle="tooltip"]').tooltip(); }) }