https://github.com/bgokden/gofuture
https://github.com/bgokden/gofuture
concurrency concurrent-programming future futures golang
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bgokden/gofuture
- Owner: bgokden
- License: apache-2.0
- Created: 2019-11-10T09:41:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-18T10:39:33.000Z (about 3 years ago)
- Last Synced: 2025-04-02T11:01:42.409Z (about 1 year ago)
- Topics: concurrency, concurrent-programming, future, futures, golang
- Language: Go
- Size: 15.6 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-future
Go-future gives an implementation similar to Java/Scala Futures.
Although there are many ways to handle this behaviour in Golang.
This library is useful for people who got used to Java/Scala Future implementation.
#### Import:
```golang
import gofuture "github.com/bgokden/gofuture"
```
#### Usage:
```golang
future := gofuture.FutureFunc(func() int {
time.Sleep(5 * time.Second)
return x * 10
})
// do something else here
// get result when needed
result := future.Get()
```
Also it is possible to use timeouts on Get
```golang
result := future.GetWithTimeout(3 * time.Second)
```
#### Note:
This is a very basic implementation where only Get and GetWithTimeout functions are implemented.
Future Get returns an interface so type casting should be done by user.
Every future creates a channel but it is not closed so it is better allow garbage collection of Future after usage.
Java Futures: https://docs.oracle.com/javase/8/docs/api/index.html?java/util/concurrent/Future.html
Scala Futures: https://docs.scala-lang.org/overviews/core/futures.html