By design, the rhino3dm javascript package has to be initialized (rhino3dm().then(rhino => { // do rhino stuff })
) before being used. This is a wasm limitation and is all fine. You can even store the value in the .then
‘callback’ to run wasm functionality synchronously afterwards.
I have been suffering in silence, though, because the emscripten tool generates a promise-like module that you cannot await
.
Finally came across this issue and wanted to share a workaround that just made my day.
import rhino3dm from 'rhino3dm'
// In some async context
await rhino3dm().then(rhino => {
// Do something with rhino
delete rhino['then']
}
This feels like the most sinful javascript I’ve ever seen but it works, even after multiple calls. I store the rhino
module somewhere and run things synchronously from there.