github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/worker/global.go (about)

     1  package worker
     2  
     3  import "github.com/15mga/kiwi/util"
     4  
     5  var (
     6  	_Global *global
     7  )
     8  
     9  func Global() *global {
    10  	return _Global
    11  }
    12  
    13  func InitGlobal() {
    14  	if _Global != nil {
    15  		return
    16  	}
    17  	_Global = NewGlobal()
    18  	_Global.worker.Start()
    19  }
    20  
    21  func NewGlobal() *global {
    22  	return &global{
    23  		worker: NewFnWorker(),
    24  	}
    25  }
    26  
    27  type global struct {
    28  	worker *FnWorker
    29  }
    30  
    31  func (o *global) Push(fn util.FnAnySlc, params ...any) {
    32  	o.worker.Push(fn, params...)
    33  }
    34  
    35  func (o *global) Dispose() {
    36  	o.worker.Dispose()
    37  }