xeokit / xeokit-xkt-utils

Deprecated JavaScript tools to generate .XKT files; replaced by https://github.com/xeokit/xeokit-convert
Other
11 stars 9 forks source link

back to asynchronous code with better error handling #2

Closed Amoki closed 4 years ago

xeolabs commented 4 years ago

It seems that we can't have await inside a non-asynch function's callback, ie.

Screenshot from 2020-10-21 11-58-26

This could be a problem making this code integrate with other utilities within examples - not quite sure how to resolve this - either to make functions like utils.loadJSON use promises, or make loadGLTFIntoXKTModel use a callback?

Amoki commented 4 years ago

An async function is a function that always returns a Promise. Meaning we can use it as a Promise and call a .then().

loadGLTFIntoModel().then(() => {
})
Amoki commented 4 years ago

In your example, you can also do

utils.loadJSON("my_model.gltf", async (json) => {
  await loadGLTFIntoModel();
});
xeolabs commented 4 years ago

Aha cool. BTW I'd like to remove the parsingCtx argument from getAttachment if that's OK with you? Just to keep that parsing context private to loadGLTFIntoXKTModel.

Amoki commented 4 years ago

OK!

xeolabs commented 4 years ago

Would you be able to fix up the examples pages in ./examples?

examples/XKTModel_load_glTF_Duplex.html examples/XKTModel_load_glTF_MAP.html examples/XKTModel_load_glTF_Schependomlaan.html

They just need to be tweaked to use the asynch bits, and need an getAttachment callback.