Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Router.isClosed #259

Closed
gf3 opened this issue Jan 7, 2022 · 2 comments
Closed

Expose Router.isClosed #259

gf3 opened this issue Jan 7, 2022 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed module: router

Comments

@gf3
Copy link

gf3 commented Jan 7, 2022

i'm attempting to write a health check for a service that uses watermill and i'd like to be able to easily determine if the router is still up and running

Router exposes a channel at .Running(), and it's possible to infer if the router is closed with a little indirection:

running := false
go func() {
  r := router.Running()

  for {
    if _, open := <-r; open {
      running = true
    } else {
      running = false
      return
    }
  }
}()

however it would be much simpler if we could simply call router.IsClosed(). perhaps there is another solution i've missed?

@roblaszczak
Copy link
Member

Hey @gf3, yes, it should be possible to easily add such a function.

It needs unit test to verify, but I think that writing the IsRunning function should like:

func (r Router) IsRunning() bool {
   select {
      case <- r.Running():
          return true
      default:
         return false
  }
}

running := false
go func() {
  r := router.Running()

  for {
    if _, open := <-r; open {
      running = true
    } else {
      running = false
      return
    }
  }
}()

But it's not really IsClosed(), because it can be not yet running. But for the health check you are probably interested with IsRunning :)

@roblaszczak
Copy link
Member

If you or anybody else have 10 mins please feel free to add that function :)

@roblaszczak roblaszczak added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed module: router labels Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed module: router
Projects
None yet
Development

No branches or pull requests

2 participants