Skip to content

Commit

Permalink
chore: optimize modem manager initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
damonto committed Jun 16, 2024
1 parent fff2f22 commit ecd7ea6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
4 changes: 0 additions & 4 deletions internal/app/handler/modem.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ EID: %s
}
m.Lock()
info, err := lpac.NewCmd(context.Background(), usbDevice).Info()
ns, _ := lpac.NewCmd(context.Background(), usbDevice).NotificationList()
for _, n := range ns {
fmt.Println(n.ICCID)
}
m.Unlock()
if err != nil {
slog.Error("failed to get eUICC info", "error", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/conversation/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var conversationsInstance *conversations
func NewConversation(bot *telebot.Bot) *conversations {
conversationsInstance = &conversations{
bot: bot,
conversations: make(map[int64]*conversation),
conversations: make(map[int64]*conversation, 10),
}
conversationsInstance.handleText()
return conversationsInstance
Expand Down
15 changes: 7 additions & 8 deletions internal/pkg/modem/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Manager struct {
reboot chan struct{}
}

var Instance *Manager
var managerInstance *Manager

func NewManager() (*Manager, error) {
mmgr, err := modemmanager.NewModemManager()
Expand All @@ -37,18 +37,17 @@ func NewManager() (*Manager, error) {
return nil, err
}

m := &Manager{
managerInstance = &Manager{
mmgr: mmgr,
modems: make(map[string]*Modem, 1),
modems: make(map[string]*Modem, 10),
reboot: make(chan struct{}, 1),
}
go m.watch()
Instance = m
return m, nil
go managerInstance.watch()
return managerInstance, nil
}

func GetManager() *Manager {
return Instance
return managerInstance
}

func (m *Manager) watch() error {
Expand All @@ -57,7 +56,7 @@ func (m *Manager) watch() error {
slog.Error("failed to watch modems", "error", err)
panic(err)
}
time.Sleep(5 * time.Second)
time.Sleep(1 * time.Second)
}
}

Expand Down

0 comments on commit ecd7ea6

Please sign in to comment.