How to make call to API from component constructor asynchronously

Hello all,

Is there a way to asynchronously make a call from a component’s constructor?

I have a compiled C# component that makes a call to an API that takes a while. The call get the same data no matter what is input to the component, so I figure it could just start when the component is constructed.

I’m not sure how to make the async task from the constructor, or how to check if the task has completed when the component gets inputs.

I have looked at that TaskCapableComponent, but I don’t think this addresses my issue.

Thanks for the help in advance.

It’s not a good idea to run execution code from the component constructor due to it’s called when Grasshopper (all components) loads at the first time.

I recomend you to check the different implementations you can find on Github (just search for code of GH_Component + async) to understand what fits better for you, or choose a ready to use implementation like this one: GitHub - specklesystems/GrasshopperAsyncComponent: Jankless Grasshopper Components