Await rhino3dm.js wasm import

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.

1 Like

Thanks for the tip @Chuck_Driesler! I ran into this myself and it’s frustrating! We’ll have to experiment with the latest version of emscripten to see if it’ll resolve these issues for us as promised

For sure! They actually just recently merged a fix for this. I’m not sure what it changes on your end, or if it’s live yet, but it looks promising.