Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 787 Bytes

README.md

File metadata and controls

46 lines (35 loc) · 787 Bytes

future

golang implementation of futures/promises

godoc reference

Install

go get github.com/sentientmonkey/future

Usage

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
}

License

MIT licensed. See the LICENSE file for details.