mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 18:57:17 -07:00
refact: refactored module SetRunning method (fixes #49)
This commit is contained in:
parent
76d6977967
commit
9c6eb70eb3
15 changed files with 103 additions and 174 deletions
|
@ -122,9 +122,16 @@ func (m *SessionModule) Running() bool {
|
|||
return m.Started
|
||||
}
|
||||
|
||||
func (m *SessionModule) SetRunning(running bool) {
|
||||
func (m *SessionModule) SetRunning(running bool, cb func()) error {
|
||||
m.StatusLock.Lock()
|
||||
defer m.StatusLock.Unlock()
|
||||
|
||||
if running && m.Started == true {
|
||||
return ErrAlreadyStarted
|
||||
} else if running == false && m.Started == false {
|
||||
return ErrAlreadyStopped
|
||||
}
|
||||
|
||||
m.Started = running
|
||||
|
||||
if *m.Session.Options.Debug == true {
|
||||
|
@ -134,4 +141,16 @@ func (m *SessionModule) SetRunning(running bool) {
|
|||
m.Session.Events.Add("mod.stopped", m.Name)
|
||||
}
|
||||
}
|
||||
|
||||
if cb != nil {
|
||||
if running == true {
|
||||
// this is the worker, start async
|
||||
go cb()
|
||||
} else {
|
||||
// stop callback, this is sync
|
||||
cb()
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue