Sha256: ae77814695d81f096cf90fcbd299d8160c86eec0d1f7fb0a22abffc69501322d

Contents?: true

Size: 1014 Bytes

Versions: 1

Compression:

Stored size: 1014 Bytes

Contents

require: "fyzmq"

class RemoteObject : BasicObject {
  def initialize {
    @context = ZMQ Context new
    @sock = @context socket: ZMQ PAIR
    Thread new: { self receive_remote }
  }

  def bind: port {
    bind_addr = "ipc://127.0.0.1:#{port}"
    "Binding #{self} to #{bind_addr}" println
    @sock bind: bind_addr
  }

  def connect_port: port {
    connect: "ipc://127.0.0.1:#{port}"
  }

  def connect: addr {
    @sock connect: addr
    "Connected #{self} to #{addr}" println
  }

  def receive_remote {
    loop: {
      "waiting" println
      msg = @sock recv
      "Got: #{msg inspect}" println
    }
  }

  def send_async: message with_params: p {
    "sending" println
    @sock send: "foo" # ('send, message, p inspect)
  }

  def to_s {
    "#<RemoteObject:#{object_id to_s: 16}>"
  }

  def inspect {
    to_s
  }
}

r = RemoteObject new

if: (ARGV includes?: "bind") then: {
  r bind: 3001
} else: {
  r connect_port: 3001
}

Thread sleep: 2

r send_async: 'to_s: with_params: 16

Thread sleep: 2

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fancy-0.6.0 lib/remote_object.fy