Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/d-exclaimation/gocurrent
Go Concurrent Utilities (Breaking changes on go 1.18)
https://github.com/d-exclaimation/gocurrent
asynchronous future futures go golang promise
Last synced: 4 days ago
JSON representation
Go Concurrent Utilities (Breaking changes on go 1.18)
- Host: GitHub
- URL: https://github.com/d-exclaimation/gocurrent
- Owner: d-exclaimation
- License: apache-2.0
- Created: 2021-10-26T11:08:25.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-28T15:55:50.000Z (almost 3 years ago)
- Last Synced: 2024-11-07T20:55:00.727Z (about 2 months ago)
- Topics: asynchronous, future, futures, go, golang, promise
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gocurrent
## Future & Promise
Deferred value that may be present in the future.
```go
package mainimport (
"github.com/d-exclaimation/gocurrent/future"
"github.com/d-exclaimation/gocurrent/result"
. "github.com/d-exclaimation/gocurrent/types"
"log"
"time"
)func main() {
fut0 := future.Async(func() (Any, error) {
time.Sleep(10 * time.Second)
return 10, nil
})fut1 := future.Map(fut0, func(any Any) Any {
return any.(int) + 2
})future.OnComplete(fut1, result.Case{
Success: func(i Any) {
log.Println(i)
},
Failure: func(err error) {
log.Fatalln(err)
},
})// ... wait for 10 seconds
// log: 12
}
```## Jet streams
Time based single topic data stream with a single upstream and multiple downstream (Broadcast / hot stream).
```go
package mainimport (
"github.com/d-exclaimation/gocurrent/streaming/jet"
. "github.com/d-exclaimation/gocurrent/types"
"log"
)func main() {
jt := jet.New()jt.On(func(i Any) {
log.Printf("[1]: %v, ", i)
})go func() {
ch := jt.Sink()
for {
select {
case i := <-ch:
log.Printf("[2]: %v, ", i)
}
}
}()go func() {
for jt.Next() {
log.Printf("[3]: %v\n", jt.Value())
}
}()jt.Up(1)
// log: [1]: 1, [2]: 1, [3]: 1
jt.Up(2)
// log: [1]: 2, [2]: 2, [3]: 2
jt.Up(3)
// log: [1]: 2, [2]: 2, [3]: 2
jt.Close()
}
```