Run the plugin. Start event processing then wait for an error or getting stopped.
(ctx context.Context)
| 87 | |
| 88 | // Run the plugin. Start event processing then wait for an error or getting stopped. |
| 89 | func (stub *stub) Run(ctx context.Context) error { |
| 90 | if !stub.m.TryLock() { |
| 91 | return fmt.Errorf("already running") |
| 92 | } |
| 93 | defer stub.m.Unlock() |
| 94 | errCh := make(chan error, 1) |
| 95 | ipc, err := stub.factory(ctx, func(err error) { |
| 96 | errCh <- err |
| 97 | }) |
| 98 | if err != nil { |
| 99 | return err |
| 100 | } |
| 101 | select { |
| 102 | case <-ctx.Done(): |
| 103 | case err = <-errCh: |
| 104 | } |
| 105 | return errors.Join(ipc.Close(), err) |
| 106 | } |
| 107 | |
| 108 | func (stub *stub) RegistrationTimeout() time.Duration { |
| 109 | return stub.registrationTimeout |