diff options
author | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-22 17:43:43 -0300 |
---|---|---|
committer | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-22 17:43:43 -0300 |
commit | a926878ddbd5a98b272c22171ce58663fc04c3e0 (patch) | |
tree | 86af256e5d9a9c06263c00adc90e5fe348008c43 /libgo/go/syscall/js/func.go | |
parent | 542730f087133690b47e036dfd43eb0db8a650ce (diff) | |
parent | 07cbaed8ba7d1b6e4ab3a9f44175502a4e1ecdb1 (diff) | |
download | gcc-devel/autopar_devel.zip gcc-devel/autopar_devel.tar.gz gcc-devel/autopar_devel.tar.bz2 |
Merge branch 'autopar_rebase2' into autopar_develdevel/autopar_devel
Quickly commit changes in the rebase branch.
Diffstat (limited to 'libgo/go/syscall/js/func.go')
-rw-r--r-- | libgo/go/syscall/js/func.go | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/libgo/go/syscall/js/func.go b/libgo/go/syscall/js/func.go index 6c145c9..da4cf68 100644 --- a/libgo/go/syscall/js/func.go +++ b/libgo/go/syscall/js/func.go @@ -22,19 +22,24 @@ type Func struct { id uint32 } -// FuncOf returns a wrapped function. +// FuncOf returns a function to be used by JavaScript. // -// Invoking the JavaScript function will synchronously call the Go function fn with the value of JavaScript's -// "this" keyword and the arguments of the invocation. -// The return value of the invocation is the result of the Go function mapped back to JavaScript according to ValueOf. +// The Go function fn is called with the value of JavaScript's "this" keyword and the +// arguments of the invocation. The return value of the invocation is +// the result of the Go function mapped back to JavaScript according to ValueOf. // -// A wrapped function triggered during a call from Go to JavaScript gets executed on the same goroutine. -// A wrapped function triggered by JavaScript's event loop gets executed on an extra goroutine. -// Blocking operations in the wrapped function will block the event loop. -// As a consequence, if one wrapped function blocks, other wrapped funcs will not be processed. -// A blocking function should therefore explicitly start a new goroutine. +// Invoking the wrapped Go function from JavaScript will +// pause the event loop and spawn a new goroutine. +// Other wrapped functions which are triggered during a call from Go to JavaScript +// get executed on the same goroutine. // -// Func.Release must be called to free up resources when the function will not be used any more. +// As a consequence, if one wrapped function blocks, JavaScript's event loop +// is blocked until that function returns. Hence, calling any async JavaScript +// API, which requires the event loop, like fetch (http.Client), will cause an +// immediate deadlock. Therefore a blocking function should explicitly start a +// new goroutine. +// +// Func.Release must be called to free up resources when the function will not be invoked any more. func FuncOf(fn func(this Value, args []Value) interface{}) Func { funcsMu.Lock() id := nextFuncID @@ -49,6 +54,7 @@ func FuncOf(fn func(this Value, args []Value) interface{}) Func { // Release frees up resources allocated for the function. // The function must not be invoked after calling Release. +// It is allowed to call Release while the function is still running. func (c Func) Release() { funcsMu.Lock() delete(funcs, c.id) |