Is there a way to prevent background task from exiting for callbacks?

I have task that is running from other module, and when it is finished it executes callback method from background service. However when calling this method i get unexpected type error. I am assuming this is because background exited without finishing. Is there a way to prevent that and keep background waiting until task is finished.



  function onTemporalEvent() as Void {
      TaskUtils.initTask(method(:onFinished)); 
    
  }

  function onFinished() as Void {
   // do something
  }