Skip to content

Instantly share code, notes, and snippets.

@vpereira

vpereira/ball.cr Secret

Created December 29, 2017 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpereira/16b06728102df5c7338cea60921533ab to your computer and use it in GitHub Desktop.
Save vpereira/16b06728102df5c7338cea60921533ab to your computer and use it in GitHub Desktop.
class Ball
property :hits
def initialize
@hits = 0
end
end
def player(name : String, table : Channel)
loop do
ball = table.receive
ball.hits += 1
puts "#{name}: #{ball.hits}"
sleep 1
table.send ball
end
end
table = Channel(Ball).new
spawn do
player("foo", table)
end
spawn do
player("bar", table)
end
table.send Ball.new # game on; toss the ball
sleep 5 # increasing it, the game goes longer
table.receive
table.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment