Ported to current weekly.
diff --git a/tomb.go b/tomb.go
index 241b5f2..eba5cb7 100644
--- a/tomb.go
+++ b/tomb.go
@@ -32,8 +32,9 @@
package tomb
import (
+ "errors"
"fmt"
- "os"
+
"sync"
)
@@ -62,11 +63,11 @@
dead chan struct{}
Dying <-chan struct{}
Dead <-chan struct{}
- reason os.Error
+ reason error
}
// The Stop error is used as a reason for a goroutine to stop cleanly.
-var Stop = os.NewError("clean stop")
+var Stop = errors.New("clean stop")
// New creates a new Tomb to track the lifecycle of a goroutine
// that is already alive or about to be created.
@@ -79,7 +80,7 @@
// Wait blocks until the goroutine is in a dead state and returns the
// reason for its death. If the reason is Stop, nil is returned.
-func (t *Tomb) Wait() os.Error {
+func (t *Tomb) Wait() error {
<-t.Dead
if t.reason == Stop {
return nil
@@ -101,7 +102,7 @@
// Fatal may be called multiple times, but only the first error is
// recorded as the reason for termination.
// The Stop value may be used to terminate a goroutine cleanly.
-func (t *Tomb) Fatal(reason os.Error) {
+func (t *Tomb) Fatal(reason error) {
if reason == nil {
panic("Fatal with nil reason")
}
@@ -119,7 +120,7 @@
// Fatalf works like Fatal, but builds the reason providing the received
// arguments to fmt.Errorf. The generated error is also returned.
-func (t *Tomb) Fatalf(format string, args ...interface{}) os.Error {
+func (t *Tomb) Fatalf(format string, args ...interface{}) error {
err := fmt.Errorf(format, args...)
t.Fatal(err)
return err
@@ -127,7 +128,7 @@
// Err returns the reason for the goroutine death provided via Fatal
// or Fatalf, or nil in case the goroutine is still alive.
-func (t *Tomb) Err() (reason os.Error) {
+func (t *Tomb) Err() (reason error) {
t.m.Lock()
reason = t.reason
t.m.Unlock()
diff --git a/tomb_test.go b/tomb_test.go
index f33feab..dbe4736 100644
--- a/tomb_test.go
+++ b/tomb_test.go
@@ -1,8 +1,10 @@
package tomb_test
import (
+ "errors"
"launchpad.net/tomb"
- "os"
+ "reflect"
+
"testing"
)
@@ -23,12 +25,12 @@
testState(t, tb, true, false, tomb.Stop)
// a non-Stop reason now will override Stop
- err := os.NewError("some error")
+ err := errors.New("some error")
tb.Fatal(err)
testState(t, tb, true, false, err)
// another non-nil reason won't replace the first one
- tb.Fatal(os.NewError("ignore me"))
+ tb.Fatal(errors.New("ignore me"))
testState(t, tb, true, false, err)
tb.Done()
@@ -38,7 +40,7 @@
func TestFatalf(t *testing.T) {
tb := tomb.New()
- err := os.NewError("BOOM")
+ err := errors.New("BOOM")
tb.Fatalf("BO%s", "OM")
testState(t, tb, true, false, err)
@@ -50,7 +52,7 @@
testState(t, tb, true, true, err)
}
-func testState(t *testing.T, tb *tomb.Tomb, wantDying, wantDead bool, wantErr os.Error) {
+func testState(t *testing.T, tb *tomb.Tomb, wantDying, wantDead bool, wantErr error) {
select {
case <-tb.Dying:
if !wantDying {
@@ -73,7 +75,7 @@
t.Error("<-Dead: should not block")
}
}
- if err := tb.Err(); err != wantErr {
+ if err := tb.Err(); !reflect.DeepEqual(err, wantErr) {
t.Errorf("Err: want %#v, got %#v", wantErr, err)
}
if wantDead && seemsDead {
@@ -82,8 +84,8 @@
if waitErr != nil {
t.Errorf("Wait: want nil, got %#v", waitErr)
}
- } else if waitErr != wantErr {
- t.Errorf("Wait: want %#v, got %#v", wantErr)
+ } else if !reflect.DeepEqual(waitErr, wantErr) {
+ t.Errorf("Wait: want %#v, got %#v", wantErr, waitErr)
}
}
}