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

Missing doc for Channel #4822

Closed
Escapingbug opened this issue Aug 11, 2017 · 5 comments
Closed

Missing doc for Channel #4822

Escapingbug opened this issue Aug 11, 2017 · 5 comments

Comments

@Escapingbug
Copy link

Thanks for this great project. I really love this language, and try to use it everywhere as much as I can. :)

But, I found there is doc missing in std, especially something about Channel. And I'm really confused about usage of this object.

Hope you guys can fix this soon. :)

@bew
Copy link
Contributor

bew commented Aug 11, 2017

Hi, I agree that the API documentation of Channel is poor right now.
If you need more information, there is a guide about concurrency in the docs: https://crystal-lang.org/docs/guides/concurrency.html

@Escapingbug
Copy link
Author

Thanks for that. But what I really need is the doc about select, and sadly, I can't find anything about that. :(

In fact, I'm trying to do non-blocking interact between threads(coroutines or fibers), in go, I can just use select to get away with not useful message sent by channels. Since there is a "select" method in Channel API, I wonder if I can do the same?

@bew
Copy link
Contributor

bew commented Aug 11, 2017

Channel.select seems to be something that shouldn't be used directly: I think you're looking for the select keyword, that allows you to wait for any channel.

The only documentation is the PR that introduced it (#3130) and the sample (see below, taken from: samples/channel_select.cr)

def generator(n : T) forall T
  channel = Channel(T).new
  spawn do
    loop do
      sleep n
      channel.send n
    end
  end
  channel
end

ch1 = generator(1)
ch2 = generator(1.5)
ch3 = generator(5)

loop do
  select
  when int = ch1.receive
    puts "Int: #{int}"
  when float = ch2.receive
    puts "Float: #{float}"
  when ch3.receive
    break
  end
end

@Escapingbug
Copy link
Author

Thanks a lot. That should be what I'm searching for. Still hope you can fix the doc problem soon. :)

@asterite
Copy link
Member

There's a lot of missing docs. The solution here is to send a PR with the docs. I don't think we'd like to track an issue for each missing piece of doc.

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

3 participants