StartAsync is part of Service interface.
(parentContext context.Context)
| 116 | |
| 117 | // StartAsync is part of Service interface. |
| 118 | func (b *BasicService) StartAsync(parentContext context.Context) error { |
| 119 | switched, oldState := b.switchState(New, Starting, func() { |
| 120 | b.serviceContext, b.serviceCancel = context.WithCancel(parentContext) |
| 121 | b.notifyListeners(func(l Listener) { l.Starting() }, false) |
| 122 | go b.main() |
| 123 | }) |
| 124 | |
| 125 | if !switched { |
| 126 | return invalidServiceStateError(oldState, New) |
| 127 | } |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | // Returns true, if state switch succeeds, false if it fails. Returned state is the state before switch. |
| 132 | // if state switching succeeds, stateFn runs with lock held. |