Skip to content

Commit

Permalink
Updated to use Celluloid::Actor and current_actor in event handler (#39)
Browse files Browse the repository at this point in the history
* Updated to use Celluloid::Actor and current_actor in event handler

* Fixed typo
  • Loading branch information
joshaidan authored and benlangfeld committed Jul 22, 2016
1 parent 8252c82 commit ef33b22
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ def handle_event(event)
end

stream = RubyAMI::Stream.new '127.0.0.1', 5038, 'manager', 'password',
->(e) { handle_event e },
->(e, stream) { handle_event e },
Logger.new(STDOUT), 10

Celluloid.join(stream) # This will block until the actor is terminated elsewhere. Otherwise, the actor will run in its own thread allowing other work to be done here.
Celluloid::Actor.join(stream) # This will block until the actor is terminated elsewhere. Otherwise, the actor will run in its own thread allowing other work to be done here.
```

Note that using `Stream.new`, the actor will shut down when the connection is lost (and in this case the program will exit). If it is necessary to restart the actor on failure, you can start it in a Celluloid supervisor:

```ruby
RubyAMI::Stream.supervise_as :ami_connection, '127.0.0.1', 5038, 'manager', 'password',
->(e) { handle_event e },
->(e, stream) { handle_event e },
Logger.new(STDOUT), 10
```

Expand All @@ -60,10 +60,10 @@ def handle_event(event, stream)
end

stream = RubyAMI::Stream.new '127.0.0.1', 5038, 'manager', 'password',
->(e) { handle_event e },
->(e, stream) { handle_event e, stream },
Logger.new(STDOUT), 10

Celluloid.join(stream) # This will block until the actor is terminated elsewhere. Otherwise, the actor will run in its own thread allowing other work to be done here.
Celluloid::Actor.join(stream) # This will block until the actor is terminated elsewhere. Otherwise, the actor will run in its own thread allowing other work to be done here.
```

Executing actions does not strictly have to be done within the event handler, but it is not valid to send AMI events before receiving a `FullyBooted` event. If you attempt to execute an action prior to this, it may fail, and `RubyAMI::Stream` will not help you recover or queue the action until the connection is `FullyBooted`; you must manage this timing yourself. That said, assuming you take care of this, you may invoke `RubyAMI::Stream#send_action` from anywhere in your code and it will return the response of the action.
Expand Down

0 comments on commit ef33b22

Please sign in to comment.