mirror of
https://github.com/lloeki/normandy.git
synced 2025-12-06 10:04:39 +01:00
examples
This commit is contained in:
parent
1921f98e47
commit
5a968ac76c
11 changed files with 219 additions and 0 deletions
30
examples/non_blocking_channel_operations.rb
Normal file
30
examples/non_blocking_channel_operations.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# https://gobyexample.com/non-blocking-channel-operations
|
||||
|
||||
require 'channel'
|
||||
|
||||
messages = Channel.new
|
||||
signals = Channel.new
|
||||
|
||||
Channel.select(messages) do |msg, c|
|
||||
case c
|
||||
when messages then puts "received message #{msg}"
|
||||
else puts 'no message received'
|
||||
end
|
||||
end
|
||||
|
||||
msg = 'hi'
|
||||
messages <- msg
|
||||
#select {
|
||||
#case messages <- msg:
|
||||
# fmt.Println("sent message", msg)
|
||||
#default:
|
||||
# fmt.Println("no message sent")
|
||||
#}
|
||||
|
||||
Channel.select(messages, signals) do |res, c|
|
||||
case c
|
||||
when messages then puts "received message #{res}"
|
||||
when signals then puts "received signal #{res}"
|
||||
else puts 'no activity'
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue