Troubleshooting: Working with webvis API#

This page may help you, if you encounter problems, while working with the webvis API.

Problems with synchronicity#

Warning

Problem: Values/nodeIDs are undefined, behavior is not as expected.

The functions of the webvis API are often asynchronous. Instead of returning the result directly, the function returns a Promise<> instead. Promises are objects and can have three different states: pending, fulfilled and rejected. Pending is the initial state, after calling the function. Fulfilled means, that the operation was completed successfully and the result is available. Rejected means that the function failed.

Tip

Solution: Use await!

While a Promise is not yet fulfilled, the expected return value is undefined. To make sure to get the correct value, you have to use await:

async function main() {
        const nodeID = 1; // some node

        await context.setProperty(nodeID, "enabled", true); // function doesn't operate further till this line completed
        const myLabel = await context.getPropterty(nodeID, "label");
        console.log(myLabel); // prints the label of the node
}

Await makes sure, that the function has completed and the return value (if not Promise<void>) is available. This is all syntactic sugar for the old handling of Promises. For more details, refer to infos about async functions.


Did you find this page useful? Please give it a rating:
Thank you for rating this page!
Any issues or feedback?
What kind of problem would you like to report?
Please tell us more about what's wrong: