Skip to content

Instantly share code, notes, and snippets.

@bibstha
Created August 2, 2016 07:59
Show Gist options
  • Save bibstha/122fb62e69faa47303af01ab0cb2cd02 to your computer and use it in GitHub Desktop.
Save bibstha/122fb62e69faa47303af01ab0cb2cd02 to your computer and use it in GitHub Desktop.
require "bundler/inline"
gemfile(true) do
source 'https://rubygems.org'
gem 'concurrent-ruby-edge', require: 'concurrent-edge'
gem 'concurrent-ruby-ext'
end
require 'concurrent/channel'
naturals = Concurrent::Channel.new(capacity: 1)
squares = Concurrent::Channel.new(capacity: 1)
Concurrent::Channel.go do
(1..12).each do |x|
naturals << x
end
naturals.close
end
Concurrent::Channel.go do
naturals.each do |x|
squares << x * x
end
squares.close
end
squares.each do |x|
puts x
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment