Sha256: 3a1c6981dad73bc183a9b0a1f64fe5e56f2fd9939e08b73d147933c81bd3b727

Contents?: true

Size: 545 Bytes

Versions: 8

Compression:

Stored size: 545 Bytes

Contents

$:.unshift File.dirname(__FILE__)+"/../../lib/"
require 'magent'

# Use: magent /path/to/this/file

class Worker
  include Magent::Actor
  channel_name "workers"
  expose :sum

  def sum(payload)
    id, *args = payload

    s = args.inject(0) { |v, a| a += v }
    send_to_client(id, {:method => :sum, :result => s})
  end

  private
  def send_to_client(id, message)
    c = Magent::GenericChannel.new("+#{id}")
    c.enqueue(message)
  end
end

Magent.register(Worker.new)

if $0 == __FILE__
  Magent::Processor.new(Worker.channel).run!
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
magent-0.6.2 examples/comm/worker.rb
magent-0.6.1 examples/comm/worker.rb
magent-0.6.0 examples/comm/worker.rb
magent-0.5.4 examples/comm/worker.rb
magent-0.5.3 examples/comm/worker.rb
magent-0.5.2 examples/comm/worker.rb
magent-0.5.1 examples/comm/worker.rb
magent-0.5.0 examples/comm/worker.rb