Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

377
Vistas
How to keep Golang WebAssembly Instance Running after error and Exit (Code:2)

I have this program to send bytes from JavaScript to Golang WebAssembly using the code:

func sendBytes(this js.Value, args []js.Value) interface{} {
    if len(args) < 1 {
        return 0
    }
    array := args[0]
    fmt.Println(array.Type())

    buf := make([]byte, array.Length())
    n := js.CopyBytesToGo(buf, array)
    fmt.Println(buf)
    return n
}

func registerCallbacks() {
    js.Global().Set("sendBytes", js.FuncOf(sendBytes))
}

When I execute sendBytes with something else than Uint8Array, I am getting my whole instance killed in the browser and I have to run it again. This is screenshot of how I execute sendBytes(). enter image description here

How can I keep it running no matter what error happened?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

According to your screenshot, when you passed a number to sendBytes(), the line of code array.Length() would lead to a panic, then the WASM code would exit. As you know sendBytes() should not be called on a number.

If you indeed need it to keep running, you can use recover in Go, similar to:

func sendBytes(this js.Value, args []js.Value) interface{} {
    defer func() {
        if r := recover(); r != nil {
            fmt.Println("Recovered from", r)
        }
    }() 

    if len(args) < 1 {
        return 0
    }
    // ...
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda