'Node WASI vs spawning a child process
In the NodeJS docs it states the following:
The WASI API provides an implementation of the WebAssembly System Interface specification. WASI gives sandboxed WebAssembly applications access to the underlying operating system via a collection of POSIX-like functions.
My question is:
What is the biggest benefit of using the WASI API over, say, spawing some other child process or similar methods of running non-nodejs code?
I would have to assume it's faster than spawning a child process, or using some C code with bindings due to the native-api.
Maybe I'm simply misunderstanding the entire idea behind WASI, which is plausable, given that part of what makes WASM so amazing is the ability to use a server-side, full blown programming language on the web (mostly), like all the crazy tools we've seen with Go/Rust.
Is this more so for the benefit of running WASM in node, natively, and again, if so, what are the benefits compared to running child processes?
Solution 1:[1]
I ended up getting my answer from a post here that was removed.
In really high-level terms, WASI is simply an (systems) interface for WASM.
I ended up finding this short 'article', if you will, super helpful too!
Just as WebAssembly is an assembly language for a conceptual machine, WebAssembly needs a system interface for a conceptual operating system, not any single operating system. This way, it can be run across all different OSs.
This is what WASI is?—?a system interface for the WebAssembly platform.
Solution 2:[2]
You have a couple of syntax issues there. You can not define multi-line strings with double or single quotes use backticks instead. And rgba does not start with a parenthesis before r and you done need a semicolon at the end;
myoutput.style.backgroundColor = `rgba(${myColor1},${myColor2},${myColor3},${myColor4})`;
Solution 3:[3]
You can use a function like this
const red = () => {
const r = 255, g = 0, b = 0, a = 1;
return `${r},${g},${b},${a}`;
}
document.body.style.backgroundColor = `rgb(${[red()]})`;
<html>
<body></body>
<html>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mytch |
| Solution 2 | Eduard |
| Solution 3 | nontechguy |
