Gopherjs: `go close(ch)` causes compile error

Created on 26 Nov 2016  路  6Comments  路  Source: gopherjs/gopherjs

http://www.gopherjs.org/play/#/uhMTBoBe53

angular.js:9937 Error: Unhandled object: *types.Builtin
bug

All 6 comments

Is there any semantic difference between go close(ch) and close(ch)?
/cc @shurcooL

In GopherJS, callbacks should not be blocked by e.g. close and in this case go is necessary. BTW, go func() { close(ch) }() worked.

close should not be considered as blocking. If it is, then that's a bug.

Ah, I was misunderstanding. Thanks. go close(ch) should be compiled without errors anyway.

close should not be blocking indeed.

Is there any semantic difference between go close(ch) and close(ch)?

Yes, there is. Consider:

ch := make(chan struct{})
close(ch)
select {
case <-ch:
    fmt.Println("a")
default:
    fmt.Println("b")
}

That program is always going to output "a" only. But if you use go close(ch), it will print "a" or "b".

In the context of GopherJS, however, it should be save to transform go close(ch) to close(ch). That's a valid way of scheduling the operation.

Do note that there are other built-ins that probably fail compilation right now, such as go delete(...)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

linkerlin picture linkerlin  路  3Comments

dmitshur picture dmitshur  路  4Comments

DapperDodo picture DapperDodo  路  6Comments

freeozyl80 picture freeozyl80  路  3Comments

hackwaly picture hackwaly  路  4Comments