gopherjs: Make "//gopherjs:blocking" the default
Suppose I have a blocking call on an interface,
var r io.Reader = T{}
n, err = r.Read(b) //gopherjs:blocking
Adding //gopherjs:blocking
allows it to work without panic: not supported by GopherJS: non-blocking call to blocking function
.
However, marking a func call as blocking does not seem to apply recursively, so if the r.Read
happens inside another func which is marked as blocking, I get a panic.
foo := func (r io.Reader, b []byte) (n int, err error) {
n, err = r.Read(b) // Adding //gopherjs:blocking here fixes it, but what if foo() is inside another library?
return
}
var r io.Reader = T{}
// I would imagine this could/should mark the r.Read(b) inside foo() as blocking too?
n, err := foo(r, b) //gopherjs:blocking
See complete example here. It works on the normal Go playground here.
Unless there’s a workaround, this is currently preventing me from implementing io.Reader and have it be usable inside standard library (which I cannot modify to add a //gopherjs:blocking
comment).
For example,
var r io.Reader = T{}
err := json.NewDecoder(r).Decode(&v) // gopherjs:blocking has no effect here,
// since r.Read() happens inside the
// encoding/json standard package.
Thanks to @dominikh for discussing/explaining/providing sample code. I wanted to make a public issue so that progress can be tracked and people can be referred to here if needed. As always, GopherJS rocks and thanks for making it! This is a testament of how far it got.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 20 (12 by maintainers)
Commits related to this issue
- js/encoding/json: Add //gopherjs:blocking to Read. This is needed as a workaround to make json.NewDecoder(reader).Decode() work, see gopherjs/gopherjs#89 for details. — committed to gophergala/correct-horse-battery-staple by dmitshur 9 years ago
- mark parent nodes as blocking, too — committed to gopherjs/gopherjs by neelance 9 years ago
- Try net/rpc/jsonrpc between backend and frontend (via GopherJS) through a websocket connection. Now that gopherjs/gopherjs#89 is resolved, this is a perfect time to try this out. — committed to shurcooL/play by dmitshur 9 years ago
Branch
assume-blocking
merged intomaster
.//gopherjs:blocking
is gone now. 😉This is an incredible milestone! Congrats!
Just want to point out that all these things are now possible: