Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / exp / ogle / abort.go
blob311a7b38e24954bfc20a669b459d356c39a14fb9
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package ogle
7 import (
8 "os"
9 "runtime"
12 // An aborter aborts the thread's current computation, usually
13 // passing the error to a waiting thread.
14 type aborter interface {
15 Abort(err os.Error)
18 type ogleAborter chan os.Error
20 func (a ogleAborter) Abort(err os.Error) {
21 a <- err
22 runtime.Goexit()
25 // try executes a computation; if the computation Aborts, try returns
26 // the error passed to abort.
27 func try(f func(a aborter)) os.Error {
28 a := make(ogleAborter)
29 go func() {
30 f(a)
31 a <- nil
32 }()
33 err := <-a
34 return err