diff options
| author | Benjamin Sanders <ben@Benjamins-MacBook-Pro.local> | 2025-10-11 10:34:24 -0400 |
|---|---|---|
| committer | Benjamin Sanders <ben@Benjamins-MacBook-Pro.local> | 2025-10-11 10:34:24 -0400 |
| commit | 5571dc766e2143e39762ff0b47c41d1c2e154f4c (patch) | |
| tree | f4f124d314a7e76c04484515aa0fd1f2e271a601 /vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old | |
| parent | 359f3309c97fc894b63e0a295c76ab298504d635 (diff) | |
Vendor bundled gems for deployment
Diffstat (limited to 'vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old')
5 files changed, 94 insertions, 0 deletions
diff --git a/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_channel.rb b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_channel.rb new file mode 100644 index 0000000..16e8d08 --- /dev/null +++ b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_channel.rb @@ -0,0 +1,43 @@ +require File.dirname(__FILE__) + '/helper' + +EM.run do + + # Create a channel to push data to, this could be stocks... + RandChannel = EM::Channel.new + + # The server simply subscribes client connections to the channel on connect, + # and unsubscribes them on disconnect. + class Server < EM::Connection + def self.start(host = '127.0.0.1', port = 8000) + EM.start_server(host, port, self) + end + + def post_init + @sid = RandChannel.subscribe { |m| send_data "#{m.inspect}\n" } + end + + def unbind + RandChannel.unsubscribe @sid + end + end + Server.start + + # Two client connections, that just print what they receive. + 2.times do + EM.connect('127.0.0.1', 8000) do |c| + c.extend EM::P::LineText2 + def c.receive_line(line) + puts "Subscriber: #{signature} got #{line}" + end + EM.add_timer(2) { c.close_connection } + end + end + + # This part of the example is more fake, but imagine sleep was in fact a + # long running calculation to achieve the value. + 40.times do + EM.defer lambda { v = sleep(rand * 2); RandChannel << [Time.now, v] } + end + + EM.add_timer(5) { EM.stop } +end diff --git a/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_queue.rb b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_queue.rb new file mode 100644 index 0000000..761ea76 --- /dev/null +++ b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_queue.rb @@ -0,0 +1,2 @@ +require File.dirname(__FILE__) + '/helper' + diff --git a/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_tick_loop_array.rb b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_tick_loop_array.rb new file mode 100644 index 0000000..81b0ae3 --- /dev/null +++ b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_tick_loop_array.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/helper' + +EM.run do + array = (1..100).to_a + + tickloop = EM.tick_loop do + if array.empty? + :stop + else + puts array.shift + end + end + + tickloop.on_stop { EM.stop } +end
\ No newline at end of file diff --git a/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_tick_loop_counter.rb b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_tick_loop_counter.rb new file mode 100644 index 0000000..58e51ff --- /dev/null +++ b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/ex_tick_loop_counter.rb @@ -0,0 +1,32 @@ +require File.dirname(__FILE__) + '/helper' + +class TickCounter + attr_reader :start_time, :count + + def initialize + reset + @tick_loop = EM.tick_loop(method(:tick)) + end + + def reset + @count = 0 + @start_time = EM.current_time + end + + def tick + @count += 1 + end + + def rate + @count / (EM.current_time - @start_time) + end +end + +period = 5 +EM.run do + counter = TickCounter.new + EM.add_periodic_timer(period) do + puts "Ticks per second: #{counter.rate} (mean of last #{period}s)" + counter.reset + end +end
\ No newline at end of file diff --git a/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/helper.rb b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/helper.rb new file mode 100644 index 0000000..835ded2 --- /dev/null +++ b/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/examples/old/helper.rb @@ -0,0 +1,2 @@ +$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') +require 'eventmachine'
\ No newline at end of file |
