第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 Web Worker 中的 onmessage 事件之前運(yùn)行 Go-WebAssembly

在 Web Worker 中的 onmessage 事件之前運(yùn)行 Go-WebAssembly

Go
慕哥6287543 2023-02-14 15:40:24
我試圖在 JavaScript Web Worker 中包含一個(gè) Go-WebAssembly 函數(shù),問(wèn)題是來(lái)自 worker 的 onmessage 事件在 WebAssembly 加載之前運(yùn)行,所以每次我調(diào)用 WebAssembly 函數(shù)時(shí)我都會(huì)收到錯(cuò)誤消息:“yourFunction is not defined ”。我希望你能幫我弄清楚如何解決這個(gè)問(wèn)題,或者你能給我一些實(shí)現(xiàn)方法。謝謝 !我的代碼的簡(jiǎn)化版本:主程序package mainimport (    "fmt"    "log"    "syscall/js")func myGoFunction(this js.Value, i []js.Value) interface{} {    //Do some hard work    fmt.Println(i[0])    return true}func main() {    js.Global().Set("myGoFunction", js.FuncOf(myGoFunction))    <-make(chan bool)}主程序const doSomething = () => {if (myArray.length > 0)    worker.postMessage({ value: myArray.shift() })}const init = () => {    if (worker) worker.terminate()    worker = new Worker('worker.js')    worker.postMessage({ a: A, b: B, bool: true })    worker.onmessage = doSomething}init()工人.jsimportScripts('wasm_exec.js');const go = new Go();WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {    go.run(result.instance);});onmessage = (e) => {    const {settings} = e.data        if (settings) {       //set some values    } else {      for (let i= 0; i < 1000000; i++)        someArray[i] = calculate(i)        postMessage({someArray})    }}const calculate = (i) => {   //Do more   //Here is where I call the go function   myGoFunction(i)}我為查看 myGoFunction 是否正在加載所做的事情是將 WebAssembly.instantiateStreaming 放入 promise 中,然后調(diào)用 onmessage 但當(dāng)然這將加載 WebAssembly.instantiateStreaming 數(shù)百萬(wàn)次并且工作完成但速度非常慢?;蛘咭苍S我以錯(cuò)誤的方式實(shí)現(xiàn)了承諾。我不知道,請(qǐng)幫忙。:D
查看完整描述

1 回答

?
臨摹微笑

TA貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個(gè)贊

您可以存儲(chǔ)返回的承諾WebAssembly.instantiateStreaming()并在您的處理程序中等待它onmessage:


const waInit = WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {

  go.run(result.instance);

});

onmessage = async (e) => {

  await waInit; // now WA is ready

  const {settings} = e.data

  // The rest of your handler


查看完整回答
反對(duì) 回復(fù) 2023-02-14
  • 1 回答
  • 0 關(guān)注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)