plugin weixin change sync rwmutex
This commit is contained in:
parent
a30bae8f66
commit
4d53cc5afe
|
@ -10,25 +10,23 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var instance *cashcoupons.CouponApiService
|
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
var onceError error
|
var errorMutex sync.RWMutex
|
||||||
var onceErrorMutex sync.Mutex
|
|
||||||
|
|
||||||
func getSrv(ctx context.Context, config *Config) (*cashcoupons.CouponApiService, error) {
|
var instanceMap = make(map[string]*cashcoupons.CouponApiService)
|
||||||
onceErrorMutex.Lock()
|
var errorMap = make(map[string]error)
|
||||||
defer onceErrorMutex.Unlock()
|
|
||||||
|
|
||||||
if onceError != nil {
|
func getSrv(ctx context.Context, c *Config) (*cashcoupons.CouponApiService, error) {
|
||||||
instance = nil
|
errorMutex.Lock()
|
||||||
onceError = nil
|
defer errorMutex.Unlock()
|
||||||
|
if errorMap[c.MchID] != nil {
|
||||||
|
instanceMap[c.MchID] = nil
|
||||||
|
errorMap[c.MchID] = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
instance, onceError = newInstance(ctx, config)
|
instanceMap[c.MchID], errorMap[c.MchID] = newInstance(ctx, c)
|
||||||
})
|
})
|
||||||
|
return instanceMap[c.MchID], errorMap[c.MchID]
|
||||||
return instance, onceError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newInstance(ctx context.Context, config *Config) (*cashcoupons.CouponApiService, error) {
|
func newInstance(ctx context.Context, config *Config) (*cashcoupons.CouponApiService, error) {
|
||||||
|
|
Loading…
Reference in New Issue