mirror of
https://github.com/syumai/workers.git
synced 2025-03-11 17:59:12 +00:00
17 lines
334 B
Go
17 lines
334 B
Go
![]() |
package jsutil
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"syscall/js"
|
||
|
)
|
||
|
|
||
|
func TryCatch(fn js.Func) (js.Value, error) {
|
||
|
fnResultVal := js.Global().Call("tryCatch", fn)
|
||
|
resultVal := fnResultVal.Get("result")
|
||
|
errorVal := fnResultVal.Get("error")
|
||
|
if !errorVal.IsUndefined() {
|
||
|
return js.Value{}, errors.New(errorVal.String())
|
||
|
}
|
||
|
return resultVal, nil
|
||
|
}
|