# help

Milos Glavinic

02/28/2022, 12:12 AM
Hi all. I am relatively new in SST. I have some situation. In my Stack constructor needs to execute some async functions. For example, I am working with MediaConvert and first I need to get media convert api endpoint. That function is promise and I need to use AWAIT in constructor to wait while info is get from the API. Of course Stack constructor cannot be async so I cannot use await. Is there any approach for this. That is not the only function where I need to use await. The only thing that come up in my mind that I will need to put all in .then(..... and have lot of nested functions on that way, which looks ugly to me. Is there any better solution. Maybe I am missing something


02/28/2022, 1:00 AM
You can put async code in your main function and pass it into the stack constructor as an argument
we are considering reworking how stack definitions work to allow async code


02/28/2022, 1:53 AM
@Milos Glavinic here’s an sample repo we put together that shows what @thdxr meant
is an async call.

Milos Glavinic

02/28/2022, 7:03 AM
Thank you so much. That is exactly what I needed. I have a few really complex stacks, so my main function become flooded. However, I sorted everything inside separate files, and looks amazing. And working as expected finally 🙂