golang implementation of futures/promises
go get github.com/sentientmonkey/future
package main
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"regexp"
"github.com/sentientmonkey/future"
)
func main() {
f := future.NewFuture(func() (future.Value, error) {
return http.Get("http://golang.org/")
})
result, err := f.Get()
if err != nil {
fmt.Printf("Got error: %s\n", err)
return
}
response := result.(*http.Response)
defer response.Body.Close()
fmt.Printf("Got result: %d\n", response.StatusCode)
// Output: Got result: 200
}
MIT licensed. See the LICENSE file for details.