【发布时间】:2019-08-19 00:36:58
【问题描述】:
我正在尝试在我的 javascript 应用程序的 WebWorker 线程上运行 wasm-flate。
使用:
<script src="https://unpkg.com/wasm-flate@0.1.11-alpha/dist/bootstrap.js"></script>
在将 flate 对象放入主线程时效果很好,但为了让它在 WebWorker 上工作,我使用了
wapm install drbh/flate
然后获取已编译的 .wasm 代码,并尝试将其加载到 WebWorker 上:
fetch("../lib/wasm_flate_bg.wasm")
.then(function(response){
response.arrayBuffer()
.then(function(buffer){
WebAssembly.compile(buffer)
.then(function(obj){
WebAssembly.instantiate(obj)
.then(function(skee){
flate=skee;
console.log(flate);
console.log(flate.exports);
console.log(flate.exports.zlib_encode);
console.log(flate.exports.zlib_encode('420'));
});
});
});
});
这一切都有效,直到我实际运行 zlib_encode 函数为止。出于某种原因,它总是返回未定义,所有函数似乎都是。但是,它们在通过 .HTML 加载时可以正常工作。
所以,我的问题是,我在这里误解了什么,我该如何解决? 谢谢。
【问题讨论】:
标签: webassembly