Skip to content

Commit

Permalink
Refactored and added additional comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anuptalwalkar committed Dec 5, 2016
1 parent b198efe commit c21008a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions service/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,20 @@ func (s *host) AddModules(modules ...ModuleCreateFunc) error {
// return the call to the caller with a Control to listen on channels
// and trigger manual shutdowns.
func (s *host) StartAsync() Control {
return s.start(false)
return s.start()
}

// Start service is used for blocking the call on service start. Start will block the
// call and yield the control to the service lifecyce manager.
// call and yield the control to the service lifecyce manager. Start will not yield back
// the control to the caller, so no code will be executed after calling Star()
func (s *host) Start() {
s.start(true)
s.start()

// block until forced exit
s.WaitForShutdown(nil)
}

func (s *host) start(waitForShutdown bool) Control {
func (s *host) start() Control {
var err error
s.locked = true
s.shutdownMu.Lock()
Expand Down Expand Up @@ -278,10 +282,6 @@ func (s *host) start(waitForShutdown bool) Control {
s.transitionState(Running)
s.shutdownMu.Unlock()

if waitForShutdown {
s.WaitForShutdown(nil)
}

return Control{
ExitChan: s.closeChan,
ReadyChan: readyCh,
Expand Down
3 changes: 2 additions & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ type Owner interface {
AddModules(modules ...ModuleCreateFunc) error

// Start service is used for blocking the call on service start. Start will block the
// call and yield the control to the service lifecyce manager.
// call and yield the control to the service lifecyce manager. No code will be executed
//after call to Start() the service.
Start()

// StartAsync service is used as a non-blocking the call on service start. StartAsync will
Expand Down

0 comments on commit c21008a

Please sign in to comment.