Skip to content

Commit

Permalink
refactor(Async): remove recover behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycumines committed Jul 26, 2019
1 parent 8bb929a commit 3b9e827
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 29 deletions.
9 changes: 0 additions & 9 deletions async.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package behaviortree

import (
"fmt"
"sync"
)

Expand Down Expand Up @@ -52,14 +51,6 @@ func Async(tick Tick) Tick {
defer func() {
done <- status
}()
defer func() {
r := recover()
if r == nil {
return
}
status.Status = Failure
status.Error = fmt.Errorf("behaviortree.Async recovered from panic: %+v", r)
}()
status.Status, status.Error = tick(children)
}()

Expand Down
20 changes: 0 additions & 20 deletions async_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,6 @@ func TestAsync_error(t *testing.T) {
}
}

func TestAsync_panic(t *testing.T) {
node := NewNode(
Async(func(children []Node) (Status, error) {
panic("some_error")
}),
nil,
)
if status, err := node.Tick(); status != Running {
t.Error("status was meant to be running but it was", status)
} else if err != nil {
t.Error("error was non-nil", err)
}
time.Sleep(time.Millisecond * 5)
if status, err := node.Tick(); status != Failure {
t.Error("status was meant to be failure but it was", status)
} else if err == nil || err.Error() != "behaviortree.Async recovered from panic: some_error" {
t.Error("unexpected error value:", err)
}
}

func TestAsync_nil(t *testing.T) {
if Async(nil) != nil {
t.Fatal("expected nil tick")
Expand Down

0 comments on commit 3b9e827

Please sign in to comment.