https://github.com/yah01/future
async-await style & future type for golang
https://github.com/yah01/future
async await future golang
Last synced: over 1 year ago
JSON representation
async-await style & future type for golang
- Host: GitHub
- URL: https://github.com/yah01/future
- Owner: yah01
- Created: 2022-03-18T06:53:00.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-22T20:19:02.000Z (over 4 years ago)
- Last Synced: 2025-01-26T00:26:03.765Z (over 1 year ago)
- Topics: async, await, future, golang
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Future
Async-Await style for Golang
## Get Started
call a function async:
```golang
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.