mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-24 22:53:52 +02:00
сделал contextmain.SetContext(ctx)
This commit is contained in:
@@ -257,7 +257,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, HandleJob func(c
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -217,7 +217,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, HandleJob func(c
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -163,7 +163,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -159,7 +159,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -18,24 +18,26 @@ var CancelContext func()
|
||||
// onceCtx - гарантирует единственное создание контеста
|
||||
var onceCtx sync.Once
|
||||
|
||||
// lockContextMain - гарантирует единственное создание контеста
|
||||
// var lockContextMain sync.Mutex
|
||||
// MutexContextMain - гарантирует единственное создание контеста
|
||||
var MutexContextMain sync.RWMutex
|
||||
|
||||
// GetContext - возвращает глобальный контекст приложения
|
||||
func GetContext() context.Context {
|
||||
//lockContextMain.Lock()
|
||||
//defer lockContextMain.Unlock()
|
||||
//
|
||||
MutexContextMain.RLock()
|
||||
defer MutexContextMain.RUnlock()
|
||||
|
||||
//if Ctx == nil {
|
||||
// CtxBg := context.Background()
|
||||
// Ctx, CancelContext = context.WithCancel(CtxBg)
|
||||
//}
|
||||
|
||||
onceCtx.Do(func() {
|
||||
CtxBg := context.Background()
|
||||
var Ctx0 context.Context
|
||||
Ctx0, CancelContext = context.WithCancel(CtxBg)
|
||||
Ctx = &Ctx0
|
||||
if Ctx == nil { //можно заполнить свой контекст, поэтому if
|
||||
CtxBg := context.Background()
|
||||
var Ctx0 context.Context
|
||||
Ctx0, CancelContext = context.WithCancel(CtxBg)
|
||||
Ctx = &Ctx0
|
||||
}
|
||||
})
|
||||
|
||||
return *Ctx
|
||||
@@ -50,3 +52,17 @@ func GetNewContext() context.Context {
|
||||
|
||||
return *Ctx
|
||||
}
|
||||
|
||||
// SetContext - устанавливает глобальный контекст, с учётом Mutex
|
||||
func SetContext(ctx *context.Context) {
|
||||
MutexContextMain.Lock()
|
||||
defer MutexContextMain.Unlock()
|
||||
Ctx = ctx
|
||||
}
|
||||
|
||||
// SetCancelContext - устанавливает функцию глобального отмены контекста, с учётом Mutex
|
||||
func SetCancelContext(cancelContext func()) {
|
||||
MutexContextMain.Lock()
|
||||
defer MutexContextMain.Unlock()
|
||||
CancelContext = cancelContext
|
||||
}
|
||||
|
||||
@@ -259,7 +259,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -289,7 +289,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -145,7 +145,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) {
|
||||
//var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -120,7 +120,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -49,7 +49,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) {
|
||||
//var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -217,7 +217,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -223,7 +223,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -237,7 +237,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -88,7 +88,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, ServiceName stri
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -212,7 +212,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, ServiceName stri
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -235,7 +235,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -295,7 +295,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -297,7 +297,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -266,7 +266,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -293,7 +293,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, Connection conne
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -66,7 +66,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, ServiceName, Ser
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -264,7 +264,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -854,7 +854,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, func_OnNewMessag
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
@@ -155,7 +155,10 @@ func Start() {
|
||||
// wg - глобальный WaitGroup приложения
|
||||
func Start_ctx(ctx *context.Context, wg *sync.WaitGroup) error {
|
||||
var err error
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
stopapp.SetWaitGroup_Main(wg)
|
||||
|
||||
err = Connect_err()
|
||||
|
||||
@@ -327,7 +327,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, eventHandler fun
|
||||
var err error
|
||||
|
||||
//запомним к себе контекст
|
||||
contextmain.Ctx = ctx
|
||||
if contextmain.Ctx != ctx {
|
||||
contextmain.SetContext(ctx)
|
||||
}
|
||||
//contextmain.Ctx = ctx
|
||||
if ctx == nil {
|
||||
contextmain.GetContext()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user