mitchellh/multistep — pull request #2 by titanous (2013-06-28 18:37:53+00:00)
Title: Fix data races, simplify

I've simplified the basic runner to check for cancellation before each step and use the close of a goroutine to synchronize waiting on Cancel().

Before this patch `go test -race` indicates data races:

```text
==================
WARNING: DATA RACE
Read by goroutine 11:
github.com/mitchellh/multistep.func·001()
$GOPATH/src/github.com/mitchellh/multistep/basic_runner.go:39 +0x17a
gosched0()
/Users/titanous/src/go-tip/src/pkg/runtime/proc.c:1218 +0x9f

Previous write by goroutine 12:
github.com/mitchellh/multistep.(*BasicRunner).Cancel()
$GOPATH/src/github.com/mitchellh/multistep/basic_runner.go:103 +0x9a
github.com/mitchellh/multistep.func·003()
$GOPATH/src/github.com/mitchellh/multistep/basic_runner_test.go:96 +0x50
gosched0()
$GOROOT/src/pkg/runtime/proc.c:1218 +0x9f

Goroutine 11 (running) created at:
github.com/mitchellh/multistep.(*BasicRunner).Run()
$GOPATH/src/github.com/mitchellh/multistep/basic_runner.go:44 +0x477
gosched0()
$GOROOT/src/pkg/runtime/proc.c:1218 +0x9f

Goroutine 12 (running) created at:
github.com/mitchellh/multistep.TestBasicRunner_Cancel()
$GOPATH/src/github.com/mitchellh/multistep/basic_runner_test.go:98 +0x5b5
testing.tRunner()
$GOROOT/src/pkg/testing/testing.go:353 +0x12f
gosched0()
$GOROOT/src/pkg/runtime/proc.c:1218 +0x9f

==================
==================
WARNING: DATA RACE
Write by goroutine 11:
runtime.mapassign1()
$GOROOT/src/pkg/runtime/hashmap.c:1289 +0x0
github.com/mitchellh/multistep.func·001()
$GOPATH/src/github.com/mitchellh/multistep/basic_runner.go:40 +0x1e7
gosched0()
$GOROOT/src/pkg/runtime/proc.c:1218 +0x9f

Previous read by goroutine 9:
runtime.mapaccess2_faststr()
/Users/titanous/src/go-tip/src/pkg/runtime/hashmap.c:473 +0x0
github.com/mitchellh/multistep.TestBasicRunner_Cancel()
$GOPATH/src/github.com/mitchellh/multistep/basic_runner_test.go:101 +0x5e1
testing.tRunner()
$GOROOT/src/pkg/testing/testing.go:353 +0x12f
gosched0()
$GOROOT/src/pkg/runtime/proc.c:1218 +0x9f

Goroutine 11 (running) created at:
github.com/mitchellh/multistep.(*BasicRunner).Run()
$GOPATH/src/github.com/mitchellh/multistep/basic_runner.go:44 +0x477
gosched0()
$GOROOT/src/pkg/runtime/proc.c:1218 +0x9f

Goroutine 9 (running) created at:
testing.RunTests()
$GOROOT/src/pkg/testing/testing.go:433 +0xaef
testing.Main()
$GOROOT/src/pkg/testing/testing.go:365 +0xab
main.main()
github.com/mitchellh/multistep/_test/_testmain.go:55 +0xda
runtime.main()
$GOROOT/src/pkg/runtime/proc.c:182 +0x91

==================
Pausing after run of step 'foo'. Press any key to continue.
PASS
Found 2 data race(s)
exit status 66
FAIL	github.com/mitchellh/multistep	1.150s
```

After, there are none:

```text
Pausing after run of step 'foo'. Press any key to continue.
PASS
ok	github.com/mitchellh/multistep	1.130s
```