Skip to content

Commit ef33b22

Browse files
joshaidanbenlangfeld
authored andcommitted
Updated to use Celluloid::Actor and current_actor in event handler (#39)
* Updated to use Celluloid::Actor and current_actor in event handler * Fixed typo
1 parent 8252c82 commit ef33b22

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ def handle_event(event)
3131
end
3232

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

37-
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.
37+
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.
3838
```
3939

4040
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:
4141

4242
```ruby
4343
RubyAMI::Stream.supervise_as :ami_connection, '127.0.0.1', 5038, 'manager', 'password',
44-
->(e) { handle_event e },
44+
->(e, stream) { handle_event e },
4545
Logger.new(STDOUT), 10
4646
```
4747

@@ -60,10 +60,10 @@ def handle_event(event, stream)
6060
end
6161

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

66-
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.
66+
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.
6767
```
6868

6969
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.

0 commit comments

Comments
 (0)