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

How to check if channel is empty? #606

Closed
bstro opened this issue Oct 28, 2016 · 4 comments
Closed

How to check if channel is empty? #606

bstro opened this issue Oct 28, 2016 · 4 comments

Comments

@bstro
Copy link

bstro commented Oct 28, 2016

What's the best way to determine if a channel is currently empty? The Buffer interface seems to describe an isEmpty method. But how do I get at the underlying buffer from a channel?

@Andarist
Copy link
Member

Andarist commented Oct 28, 2016

Just yield flush(channel)

@bstro
Copy link
Author

bstro commented Oct 28, 2016

Thanks for the reply @Andarist; for my use case, I just need to know if the channel is empty, but not actually empty it.

@Andarist
Copy link
Member

Andarist commented Oct 29, 2016

Well, you can always pass a buffer manually, so you have reference to it and you can check its isEmpty method

import { buffers } from 'redux-saga'
import { actionChannel } from 'redux-saga/effects'

function* saga() {
  const buffer = buffers.fixed() // or some other buffer type
  const chan = yield actionChannel('ACTION_TYPE', buffer)

  if (buffer.isEmpty()) {
     //...  
  }
}

@bstro
Copy link
Author

bstro commented Oct 31, 2016

Perfect. Thanks!!

@bstro bstro closed this as completed Oct 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants