Sha256: 9434842300131608e9ad837f5215698c9ba857244029d91bfbce097df8fffcd9

Contents?: true

Size: 646 Bytes

Versions: 1

Compression:

Stored size: 646 Bytes

Contents

require("actor")
class Actor {
  alias_method: '! for_ruby: '<<
}

# Execute with Rubinius: rbx ex1.rb

def error_loop: block{
  try {
    loop: block
  } catch Exception => ex {
    ex message println
    ex backtrace join: "\n"
  }
}

pong = nil
ping = Actor spawn() {
  error_loop: {
    count = Actor receive()
    "." print
    { return count println } if: (count > 1000)
    pong ! (count + 1)
  }
}
pong = Actor.spawn() {
  error_loop: {
    count = Actor receive()
    "-" print
    { return count println } if: (count > 1000)
    ping ! (count + 1)
  }
}
ping ! 1

# Let the actors process while the main thread sleeps...
Thread sleep: 1

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fancy-0.3.3 examples/actor.fy