I have a part of code to retrieve some hardware device connected to PC. I also use a 3rd party library to retrieve these devices. I have done it in this way:
console.log("before");
// some code here
(async () => {
await 3dpartlibrary.getDevices().then(function (myDevices) {
for (var i = 0; i < myDevices.length; i++) {
console.log(myDevices[i]); // i need this information to continue execution
}
});
})();
// here i would have a list of devices and i choose one from the list
console.log("after");
But the execution continues and I have the console messages after a bit of time. Actually i have in console the messages: before, after, and then devices.
I have put async in this way because cannot put in top of the function.
Probably async wait promise to resolve but the underneath code is goind ahead, i i would to obtain my list befor to go console.log("after") point.
How can I wait to have a list of devices before to continue execution?