A javascript Engine base on Goja inspired by k6
engine.StopEventLoopXXX
package main
import (
"github.com/ZenLiuCN/engine"
)
func main() {
vm := engine.Get()
defer vm.Free()
v, err := vm.RunJs(
console.log("Begin "+"For timeout") new Promise((r, j) => { console.log("job 0") setTimeout(()=>r(1),1000) }).then(v => { console.log("job",v) return new Promise((r, j) => { setTimeout(()=>r(v+1),1000) })}).then(v => { console.log("job",v) return new Promise((r, j) => { setTimeout(()=>r(v+1),1000) }) }).then(v => { console.log("job",v) return new Promise((r, j) => { setTimeout(()=>r(v+1),2000) }) }).then(v => { console.log("job",v) return new Promise((r, j) => { setTimeout(()=>r(v+1),2000) }) })
)
halts := vm.Await() //manual await task done
if !halts.IsZero(){
panic("task not done")
}
if err!=nil{
panic(err)
}
println(v)
}
### manual
```go
package main
import (
"github.com/ZenLiuCN/engine"
"time"
)
func main() {
vm := engine.Get()
defer vm.Free()
v, err := vm.RunJs(
`
console.log("Begin "+"For timeout")
new Promise((r, j) => {
console.log("job 0")
setTimeout(()=>r(1),1000)
}).then(v => {
console.log("job",v)
return new Promise((r, j) => {
setTimeout(()=>r(v+1),1000)
})}).then(v => {
console.log("job",v)
return new Promise((r, j) => {
setTimeout(()=>r(v+1),1000)
})
}).then(v => {
console.log("job",v)
return new Promise((r, j) => {
setTimeout(()=>r(v+1),2000)
})
}).then(v => {
console.log("job",v)
return new Promise((r, j) => {
setTimeout(()=>r(v+1),2000)
})
})`)
halts := vm.AwaitTimeout(time.Second * 5) //manual await task done for limited time
if !halts.IsZero(){
panic("task not done within 5 seconds")
}
if err!=nil{
panic(err)
}
println(v)
}
package main
import (
"github.com/ZenLiuCN/engine"
"time"
)
func main() {
vm := engine.Get()
defer vm.Free()
v, err := vm.RunJsTimeout(`import {Second, sleep} from 'go/time'
new Promise((r, j) => {
sleep(Second)
r(1)
}).then(v => {
console.log(v)
return new Promise((r, j) => {
sleep(Second)
r(v+1)
})
}).then(v => {
console.log(v)
return new Promise((r, j) => {
sleep(Second)
r(v+1)
})
}).then(v => {
console.log(v)
return new Promise((r, j) => {
sleep(Second*2)
r(v+1)
})
}).then(v => {
console.log(v)
return new Promise((r, j) => {
sleep(Second*2)
r(v+1)
})
})
`, time.Second*8)
if err != nil {
panic(err) // if error is ErrTimeout, the value is HaltJobs
}
println(v)
}
Simple wrapper for goja.Runtime with extended abilities.
Simple wrapper for goja.Program
js:"name"
to mapping fields to js propertyjs:"-"
to ignore export fieldUUUlllUll
=> uuUllUll
UlllUll
=> ullUll
XlllUll
=> llUll
XUllUll
=> UllUll
require
Simple support for CommonJs, ES script and TypeScript also compiled as CJS script, inspire by k6
d.ts
datago/compiler
built-in compiler for both typescript and javascriptgo/esbuild
expose esbuild to jscomponents
go/engine
: use engine in scripts, maybe not to use too many russian dollsgo/buffer
: golang byte slice and bytes.Buffergo/hash
:golang hash functionsgo/codec
:golang codec functions, include base64 ...go/crypto
: golang cryptogo/os
: golang os , not full functionsgo/io
: golang io module
go/chan
: golang chan type only
pluggable modules
go/sqlx
: sqlx with pgx
mysql
and sqlite
drivercomponents
go/excel
: excel reading or generatecomponents
go/fetch
: base function done, improve for compact with browser fetch.go/pug
: jade(pug) compiler
components
go/minify
: file minifycomponents
dev
draft
draft