Use Case
I have a piechart that can be updated when a user clicks a button or selects an item from a dropdown. Now instead of having the same script in the dropdown and the button i want to have a script in 1 place. In vision what i would do is create a custom function in the pie chart component and then use system.util.invokeAsynchronous on the button and the dropdown to call the custom function and update the pie chart.
Can something similar be done for perspective?
One possible way to handle is to put this code in a message handler, and let the button click or dropdown call this message handler. The button click will return instantly and MH will update the pie chart as a separate trigger.
You absolutely can invoke async threads. It's a relatively heavyweight operation though, and I would not recommend it just for slightly better developer ergonomics. Embrace message handlers so that work happens on existing Perspective worker threads as much as possible.
As an aside, doing this in Vision is dangerous (prone to locking up the event dispatch thread) unless you're leaping from that async thread back to the EDT with system.util.invokeLater
. If you are, ignore this, but if you aren't, you should really fix your script(s).
3 Likes