Skip to content

Commit 2e2e2b6

Browse files
author
Luca Bianconi
committed
wip
1 parent ca4a7d4 commit 2e2e2b6

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

Diff for: arduino/cores/packagemanager/package_manager.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ func (pmb *Builder) BuildIntoExistingPackageManager(target *PackageManager) {
9595
target.profile = pmb.profile
9696
if target.discoveryManager != nil {
9797
target.discoveryManager.Clear()
98+
} else {
99+
target.discoveryManager = pmb.discoveryManager
98100
}
99-
target.discoveryManager = pmb.discoveryManager
100101
target.userAgent = pmb.userAgent
101102
}
102103

Diff for: arduino/discovery/discovery.go

+1
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ func (disc *PluggableDiscovery) Quit() {
379379
if _, err := disc.waitMessage(time.Second * 5); err != nil {
380380
logrus.Errorf("Quitting discovery %s: %s", disc.id, err)
381381
}
382+
disc.stopSync()
382383
disc.killProcess()
383384
}
384385

Diff for: arduino/discovery/discoverymanager/discoverymanager.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ func (dm *DiscoveryManager) Clear() {
6565
logrus.Infof("Closed and removed discovery %s", d.GetID())
6666
}
6767
}
68+
dm.discoveriesRunning = false
6869
dm.discoveries = map[string]*discovery.PluggableDiscovery{}
6970
}
7071

72+
// DiscoveryRunning returns boolean representing the running status of discoveries
73+
func (dm *DiscoveryManager) DiscoveryRunning() bool {
74+
return dm.discoveriesRunning
75+
}
76+
7177
// IDs returns the list of discoveries' ids in this DiscoveryManager
7278
func (dm *DiscoveryManager) IDs() []string {
7379
ids := []string{}
@@ -194,12 +200,14 @@ func (dm *DiscoveryManager) startDiscovery(d *discovery.PluggableDiscovery) (dis
194200
return fmt.Errorf("%s: %s", tr("starting discovery %s", d.GetID()), err)
195201
}
196202

197-
go func() {
203+
go func(d *discovery.PluggableDiscovery) {
198204
// Transfer all incoming events from this discovery to the feed channel
199205
for ev := range eventCh {
206+
// here from discovery to discovery manager
200207
dm.feed <- ev
201208
}
202-
}()
209+
logrus.Info("Discovery event channel closed %s. Exiting goroutine.", d.GetID())
210+
}(d)
203211
return nil
204212
}
205213

Diff for: commands/instances.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,23 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
261261
},
262262
})
263263
}
264-
264+
var shouldStartDiscovery bool
265265
{
266266
// We need to rebuild the PackageManager currently in use by this instance
267267
// in case this is not the first Init on this instances, that might happen
268268
// after reinitializing an instance after installing or uninstalling a core.
269269
// If this is not done the information of the uninstall core is kept in memory,
270270
// even if it should not.
271+
272+
exp, release := instance.pm.NewExplorer()
273+
// register whether the discoveries are running, if so we need to start them in
274+
// for the previous watchers to keep receiving events
275+
if exp.DiscoveryManager() != nil && exp.DiscoveryManager().DiscoveryRunning() {
276+
shouldStartDiscovery = true
277+
} else {
278+
shouldStartDiscovery = false
279+
}
280+
release()
271281
pmb, commitPackageManager := instance.pm.NewBuilder()
272282

273283
loadBuiltinTools := func() []error {
@@ -443,6 +453,9 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
443453
responseError(s)
444454
}
445455

456+
if shouldStartDiscovery {
457+
pme.DiscoveryManager().Start()
458+
}
446459
// Refreshes the locale used, this will change the
447460
// language of the CLI if the locale is different
448461
// after started.

0 commit comments

Comments
 (0)