rdleal / go-async Goto Github PK
View Code? Open in Web Editor NEWAsync utilities for Golang
License: MIT License
Async utilities for Golang
License: MIT License
Hi,
Currently when sending multiple payload in async.Auto
mode, for each payload, I need to create async.Auto
. So trying to understand if there's any way we could do something like this.
auto, _ := sync.Auth(context.Background(), async.FuncMap{...}, Option...)
result, _ := auto.Process("Argument)
``
Thanks for this awesome tool. I was looking for simple workflow tool like this.
I've some questions:
I tested this tool with this code and seems the performance is slow when using goroutine
type msg struct {
Greet, Name string
}
fm := async.FuncMap{
"reader": strings.NewReader,
"decoder": async.DependsOn("reader").To(utils.Json.NewDecoder),
"parser": async.DependsOn("decoder").To(func(d *jsoniter.Decoder) (msg, error) {
var m msg
err := d.Decode(&m)
return m, err
}),
"greet": async.DependsOn("parser").To(func(m msg) string {
return strings.Title(m.Greet)
}),
"name": async.DependsOn("parser").To(func(m msg) string {
return strings.Title(m.Name)
}),
"greeter": async.DependsOn("greet", "name").To(func(greet, name string) string {
return fmt.Sprintf("%s, %s!", greet, name)
}),
}
for i := 0; i < 100; i++ {
go func(j int) {
jsonStr := `{"greet": "hello", "name" : "gopher-` + strconv.Itoa(j) + `"}`
start := time.Now()
fnc, err := async.Auto(context.Background(), fm, async.WithArgs(jsonStr))
if err != nil {
log.Fatal(err)
}
for fn := range fnc {
res, err := fn.Returned()
if err != nil {
log.Fatal(err)
}
fmt.Println(res[0]) // Hello, Gopher!
}
fmt.Println(fmt.Sprintf("%s", time.Since(start)))
}(i)
}
Result:
Hello, Gopher-100!
1.239477ms
Hello, Gopher-100!
28.85µs
Hello, Gopher-100!
1.329145ms
Hello, Gopher-100!
1.231549ms
Hello, Gopher-100!
23.32µs
Hello, Gopher-100!
1.287589ms
Hello, Gopher-100!
1.246905ms
Hello, Gopher-100!
29.173µs
Some suggestions:
For now I've been using this library to make it happen using Redis and Queue
https://github.com/hibiken/asynq
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.