future

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2019 License: MIT Imports: 2 Imported by: 0

README

Go Future Last release Documentation

Go Report Card

Branch Status Coverage
master Build Status Coveralls

go-future is an implementation of future in Go.

Example

package main

import (
    "fmt"

    "github.com/euskadi31/go-future"
)

func asyncFunc() *future.Future {
    f := future.New()

    go func(f *future.Future) {
        f.Value("my async value")
    }(f)

    return f
}

func main() {
    f := asyncFunc();

    v, err := f.Get()
    if err != nil {
        panic(err)
    }

    fmt.Println(v)

}

With Fill

package main

import (
    "fmt"

    "github.com/euskadi31/go-future"
)

func asyncFunc() *future.Future {
    f := future.New()

    go func(f *future.Future) {
        f.Value("my async value")
    }(f)

    return f
}

func main() {
    f := asyncFunc();

    var v string
    if err := f.Fill(&v); err != nil {
        panic(err)
    }

    fmt.Println(v)
}

License

go-future is licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Future

type Future struct {
	// contains filtered or unexported fields
}

Future struct

func Error

func Error(err error) *Future

Error return future error

func New

func New() *Future

New Future

func Value

func Value(value interface{}) *Future

Value return future value

func (*Future) Close

func (f *Future) Close()

Close future

func (*Future) Error

func (f *Future) Error(err error) *Future

Error set error to Future

func (*Future) Fill

func (f *Future) Fill(dest interface{}) error

Fill dest var

func (*Future) Get

func (f *Future) Get() (interface{}, error)

Get result or error

func (*Future) Value

func (f *Future) Value(value interface{}) *Future

Value set value to Future

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL