Sha256: 1a337b6ada3222d8f11a3a719ebc5b712ed21bdffafc143b9b93ce651db8a7e7

Contents?: true

Size: 871 Bytes

Versions: 4

Compression:

Stored size: 871 Bytes

Contents

# encoding: utf-8

#   Task vent to be used in conjunction with task_worker.rb
#   and task_sink.rb
#   Binds PUSH socket to tcp://localhost:5557
#   Sends batch of tasks to task_workers via that socket

require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rxs')

context = XS::Context.create()

# Socket to send messages on
sender = context.socket(XS::PUSH)
sender.bind("tcp://*:5557")

puts "Press enter when the workers are ready..."
$stdin.read(1)
puts "Sending tasks to workers..."

# The first message is "0" and signals start of batch
sender.send_string('0')

# Send 100 tasks
total_msec = 0  # Total expected cost in msecs
100.times do
  workload = rand(100) + 1
  total_msec += workload
  $stdout << "#{workload}."
  sender.send_string(workload.to_s)
end

puts "Total expected cost: #{total_msec} msec"
Kernel.sleep(1)  # Give Crossroads time to deliver

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ffi-rxs-1.2.1 examples/task_vent.rb
ffi-rxs-1.2.0 examples/task_vent.rb
ffi-rxs-1.1.0 examples/task_vent.rb
ffi-rxs-1.0.1 examples/task_vent.rb