github.com/blend/go-sdk@v1.20220411.3/cron/default.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package cron 9 10 import "sync" 11 12 var ( 13 _default *JobManager 14 _defaultLock sync.Mutex 15 ) 16 17 // Default returns a shared instance of a JobManager. 18 // If unset, it will initialize it with `New()`. 19 func Default() *JobManager { 20 if _default == nil { 21 _defaultLock.Lock() 22 defer _defaultLock.Unlock() 23 24 if _default == nil { 25 _default = New() 26 } 27 } 28 return _default 29 } 30 31 // SetDefault sets the default job manager. 32 func SetDefault(jm *JobManager) { 33 _defaultLock.Lock() 34 _default = jm 35 _defaultLock.Unlock() 36 }