Skip to content

yah01/future

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Future

Async-Await style for Golang

Get Started

call a function async:

package main

import (
	"fmt"
	"strings"
	"time"

	. "github.com/yah01/future"
)

func DelayJoin(names ...string) string {
	time.Sleep(time.Second)
	result := strings.Join(names, ", ")

	return result
}

func main() {
	future := Submit(func() (string, error) {
		res := DelayJoin("yah01", "zer0ne")
		return res, nil
	})

	fmt.Printf("hello %s", future.Value())
}

An async call returns a future, which contains the return value of the method. Invoking Await() method to wait for the result.

About

async-await style & future type for golang

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages