fanliao / go-promise Goto Github PK
View Code? Open in Web Editor NEWA library implement futrue and promise
License: MIT License
A library implement futrue and promise
License: MIT License
this link - https://github.com/fanliao/go-promise/blob/master - returns 404. permission issue?
func PromisePipelining1() {
task1 := func() (r interface{}, err error) {
return 10, errors.New("error")
}
task2 := func(v interface{}) (r interface{}, err error) {
return v.(int) * 2, nil
}
f,ok := promise.Start(task1).Pipe(task2)
if ok {
r, err := f.Get() //return 20
fmt.Println(r,err)
}
}
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
github.com/fanliao/go-promise.(*Future).Get(0xc0420b8980, 0xc042083f38, 0x1, 0x1, 0xc0420b8980)
D:/Code/golang/src/github.com/fanliao/go-promise/future.go:138 +0x4f
main.PromisePipelining1()
D:/Code/golang/src/studygo/futrue/future.go:148 +0xd4
main.main()
D:/Code/golang/src/studygo/futrue/future.go:16 +0x27
exit status 2
In project subtiltle
A library implement futrue and promise
Should be
A library implement future and promise
I think it would be great being able to wait for Resolve
method to actually run its callbacks, or at least to have two methods like Resolve
and ResolveAsync
.
I'd expect the following code to print "running callback" but this doesn't happen since promise.Resolve
is using a go routine and this is not clear.
package main
import "github.com/fanliao/go-promise"
import "fmt"
func main() {
p := promise.NewPromise()
p.OnSuccess(func(v interface{}) {
fmt.Println("running callback")
})
p.Resolve(nil)
}
Thank you!
我用的就是GitHub上的测试例子
task := func(param interface{} //=========== here, task with some param
)(r interface{}, err error){
url := "http://example.com/"
resp, err := http.Get(url)
defer resp.Body.Close()
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, nil
}
// when start an promise how to pass param for task?
f := promise.Start(task).OnSuccess(func(v interface{}) {
}
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.