问题描述
我正在研究一个javascript项目,该项目最初具有用JS编写的所有复杂逻辑.但是它很慢,因此由于架构限制,我们现在已将所有复杂的逻辑移植到golang,我们无法调用golang的API,因此我们转向了wasm,在其中将golang代码构建到wasm文件中并从js代码中调用从而消除了API调用.
I am working on a javascript project which initially had all complex logic written in JS. However it was very slow so we had ported all the complex logic to golang now due to architectural constraints we cannot call APIs of the golang, so we moved towards wasm where you build your golang code into a wasm file and call it from your js code and hence eliminating API calls.
现在一切正常,直到我们收到一个复杂的对象,如果您通过wasm执行它会花费很多时间,但是如果您通过golang运行它只需要几秒钟.所以我的问题是我可以在浏览器中加载的wasm文件中实现多线程吗?
Now everything was working fine until we have received some complex object which takes a lot of time if you execute through wasm but takes only few seconds if you run it through golang. So my question is can I implement multithreading into wasm file loaded in browser?
推荐答案
所以我的问题是我可以在浏览器中加载的wasm文件中实现多线程吗?
So my question is can I implement multithreading into wasm file loaded in browser?
总而言之:否
WASM尚未完全支持多线程.它仍然只是一个提案.就是说,已经有一个问题针对Go/WASM进行跟踪.
Multithreading isn't officially supported in WASM at all yet. It's still just a proposal. That said, there's already an issue tracking this for Go/WASM.
因此,实际上,这意味着乐观地认为Go 1.14是第一个可能包含(实验性)WASM Threading支持的Go版本,该支持可能会在2020Q1推出.稳定的支持可能至少还需要一个Go发布周期,所以也许2020Q3可以在生产中使用它.
So what this means, in practical terms, is that, optimistically, Go 1.14 is the first Go version likely to include (experimental) WASM Threading support, which will probably come out 2020Q1. Stable support likely will take at least one more Go release cycle, so perhaps 2020Q3 you'll be able to use this in production.
这篇关于如何在使用golang创建的wasm中实现多线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!