mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Use singleton in other places as well
This commit is contained in:
parent
1f997357a9
commit
743e469795
7 changed files with 39 additions and 104 deletions
|
@ -5,14 +5,14 @@ package cmd
|
|||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/navidrome/navidrome/server/events"
|
||||
|
||||
"github.com/google/wire"
|
||||
"github.com/navidrome/navidrome/core"
|
||||
"github.com/navidrome/navidrome/core/agents/lastfm"
|
||||
"github.com/navidrome/navidrome/persistence"
|
||||
"github.com/navidrome/navidrome/scanner"
|
||||
"github.com/navidrome/navidrome/scheduler"
|
||||
"github.com/navidrome/navidrome/server"
|
||||
"github.com/navidrome/navidrome/server/events"
|
||||
"github.com/navidrome/navidrome/server/nativeapi"
|
||||
"github.com/navidrome/navidrome/server/subsonic"
|
||||
)
|
||||
|
@ -23,7 +23,7 @@ var allProviders = wire.NewSet(
|
|||
nativeapi.New,
|
||||
persistence.New,
|
||||
lastfm.NewRouter,
|
||||
GetBroker,
|
||||
events.GetBroker,
|
||||
)
|
||||
|
||||
func CreateServer(musicFolder string) *server.Server {
|
||||
|
@ -71,41 +71,3 @@ func createScanner() scanner.Scanner {
|
|||
scanner.New,
|
||||
))
|
||||
}
|
||||
|
||||
// Broker must be a Singleton
|
||||
var (
|
||||
onceBroker sync.Once
|
||||
brokerInstance events.Broker
|
||||
)
|
||||
|
||||
func GetBroker() events.Broker {
|
||||
onceBroker.Do(func() {
|
||||
brokerInstance = createBroker()
|
||||
})
|
||||
return brokerInstance
|
||||
}
|
||||
|
||||
func createBroker() events.Broker {
|
||||
panic(wire.Build(
|
||||
events.NewBroker,
|
||||
))
|
||||
}
|
||||
|
||||
// Scheduler must be a Singleton
|
||||
var (
|
||||
onceScheduler sync.Once
|
||||
schedulerInstance scheduler.Scheduler
|
||||
)
|
||||
|
||||
func GetScheduler() scheduler.Scheduler {
|
||||
onceScheduler.Do(func() {
|
||||
schedulerInstance = createScheduler()
|
||||
})
|
||||
return schedulerInstance
|
||||
}
|
||||
|
||||
func createScheduler() scheduler.Scheduler {
|
||||
panic(wire.Build(
|
||||
scheduler.New,
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue