Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tame trapKill

  • Loading branch information...
commit 8fffd48e596d87fbba64a8092958dc4776c3d2a1 1 parent 3cdfe13
@mental authored
Showing with 27 additions and 27 deletions.
  1. +9 −10 README.md
  2. +16 −16 spec/ActorSpec.coffee
  3. +2 −1  src/Actor.coffee
View
19 README.md
@@ -320,16 +320,15 @@ Normally, when an actor receives a kill, it will immediately
exit. `trapKill` allows for more nuanced behavior
than the default.
-This passed-in function receives two arguments: the id of
-the originating (not the receiving!) actor, and the reason
-for the kill. If it throws an exception, the actor will
-die with that exception.
-
-Note that the callback does NOT run in the context of an
-actor, so functions like `receive` should not be used.
-
-Typically, `sendback` is used with `trapKill` to redirect
-the kill to the actor's mailbox as a regular message.
+This passed-in callback function receives two arguments:
+the id of the originating (not the receiving!) actor, and
+the reason for the kill. It should return a message to
+be delivered to the actor receiving the kill. If the
+function instead throws an exception, then the receiving
+actor will die with that exception.
+
+The callback should have no side-effects and should avoid
+state-modifying calls to the WebActors API.
### WebActors.sendback(args...) -> cb
View
32 spec/ActorSpec.coffee
@@ -62,7 +62,7 @@ describe "A WebActors Actor", ->
received = []
actor_a_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
WebActors.receive $ARG, (m) ->
received.push m
@@ -78,7 +78,7 @@ describe "A WebActors Actor", ->
received = []
actor_a_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
WebActors.receive $ARG, (m) ->
received.push m
@@ -94,7 +94,7 @@ describe "A WebActors Actor", ->
received = []
actor_a_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
WebActors.receive $ARG, (m) -> received.push m
actor_b_id = WebActors.spawn ->
@@ -128,7 +128,7 @@ describe "A WebActors Actor", ->
received = []
actor_a_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
WebActors.receive "go", ->
WebActors.kill actor_b_id, "testing"
WebActors.receive $ARG, (m) -> received.push m
@@ -147,7 +147,7 @@ describe "A WebActors Actor", ->
passed = false
root_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
actor_a_id = "root:foo"
WebActors.link actor_a_id
WebActors.receive [actor_a_id, ANY], -> passed = true
@@ -158,7 +158,7 @@ describe "A WebActors Actor", ->
passed = false
root_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
actor_a_id = WebActors.spawnLinked ->
WebActors.receive ANY, ->
@@ -176,7 +176,7 @@ describe "A WebActors Actor", ->
passed = false
root_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
actor_a_id = WebActors.spawn ->
WebActors.link root_id
throw "foo"
@@ -188,7 +188,7 @@ describe "A WebActors Actor", ->
passed = false
root_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
actor_a_id = WebActors.spawn ->
WebActors.link root_id
@@ -212,7 +212,7 @@ describe "A WebActors Actor", ->
passed = false
root_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
actor_a_id = WebActors.spawnLinked ->
WebActors.send root_id, "go"
@@ -240,7 +240,7 @@ describe "A WebActors Actor", ->
passed = false
root_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
actor_a_id = WebActors.spawnLinked ->
WebActors.trapKill (killer_id, reason) -> throw "foobar"
@@ -261,7 +261,7 @@ describe "A WebActors Actor", ->
passed = false
root_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
ready = true
WebActors.receive [null, "foobar"], ->
passed = true
@@ -278,7 +278,7 @@ describe "A WebActors Actor", ->
body_run = false
WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
actor_a_id = WebActors.spawnLinked ->
body_run = true
@@ -327,7 +327,7 @@ describe "WebActors.injectEvent", ->
received = []
actor_a_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback("blah")
+ WebActors.trapKill (killer_id, reason) -> ["blah", killer_id, reason]
WebActors.receive WebActors.$ARG, (message) ->
received.push(message)
@@ -342,7 +342,7 @@ describe "WebActors.injectEvent", ->
received = []
actor_a_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback("blah")
+ WebActors.trapKill (killer_id, reason) -> ["blah", killer_id, reason]
WebActors.receive WebActors.$ARG, (message) ->
received.push(message)
@@ -361,7 +361,7 @@ describe "WebActors.injectEvent", ->
ready = false
actor_id = WebActors.spawn ->
- WebActors.trapKill WebActors.sendback("blah")
+ WebActors.trapKill (killer_id, reason) -> ["blah", killer_id, reason]
ready = true
WebActors.receive WebActors.$ARG, (message) ->
received.push(message)
@@ -479,7 +479,7 @@ describe "WebActors.setDefaultGateway", ->
passed = false
WebActors.spawn ->
- WebActors.trapKill WebActors.sendback()
+ WebActors.trapKill (killer_id, reason) -> [killer_id, reason]
WebActors.link "junk:bogus"
WebActors.receive ["junk:bogus", WebActors.ANY], ->
passed = true
View
3  src/Actor.coffee
@@ -73,7 +73,8 @@ class LocalActor
saved_actor = current_actor
current_actor = NULL_ACTOR
try
- @kill_handler(killer_id, reason)
+ message = @kill_handler(killer_id, reason)
+ WebActors.send @actor_id, message
catch e
@shutdown(e)
finally
Please sign in to comment.
Something went wrong with that request. Please try again.