rogchap / v8go

Execute JavaScript from Go
https://rogchap.com/v8go
BSD 3-Clause "New" or "Revised" License
3.22k stars 221 forks source link

Multiple context managed by a load balancing technique #410

Open anzalabidi opened 3 months ago

anzalabidi commented 3 months ago
iso := v8.NewIsolate()
    defer iso.Dispose()
    if iso == nil {
        log.Fatal("Failed to create V8 isolate")
    }
    v8Ctx := v8.NewContext(iso)
    defer v8Ctx.Close()

    _, err = v8Ctx.RunScript(backendBundle, "bundle.js")
    if err != nil {
        log.Fatalf("Failed to evaluate bundled script: %v", err)
    }
    val, err := v8Ctx.RunScript(fmt.Sprintf("renderApp(%s)", string(propsJSON)), "render.js")
    if err != nil {
        log.Fatalf("Failed to render React component: %v", err)
    }

Need to make this usable via context pool.