What function/file is responsible for loading the viewport? What is the workflow of the viewer when hydrating the segmentation?

I am trying to implement automatic loading of segmentation onto the viewport.
I tried various approaches to achieve this, I created a function setSeries that has a setTimeout(delay: 1000ms) function that setsDisplaySet of segmentation to the viewport if any segmentation is present, I have come across the problem that is for some reason setSeries gets executed before the viewport is loaded, whole viewport freezes (the same reason I am using a setTimeout function), In order to bypass this problem, I have to use any callback, promise or subscribe to any event that gets triggered after loading the viewport.

  • Using OHIF v3.8

I want to understand the workflow of OHIF viewer, and its functionalities to resolve the issue and to not get stuck in such issues.

If anyone who could help me with this, any help however small it may be is appreciated